How to make datetime callable in python module?

Viewed 44
from datetime import datetime, timedelta
start = datetime.now()
if datetime.now() - start() > timedelta(seconds=5):

'datetime.datetime' object is not callable

the problem in the 'if' string. Thanks if you can help me.

1 Answers

You should not write parenthesis for the start():

from datetime import datetime, timedelta

start = datetime.now()
if datetime.now() - start > timedelta(seconds=5):
    # …
    pass

start is a datetime object, and it does not make much sense to perform a function call on a datetime object.

Related