Skip to content
Advertisement

Python datetime module problems

I’m using the datetime module in python3.7. When I run it from terminal it throws an error:

File "/home/user/Desktop/Yazılım/datetime.py", line 2, in <module>
x=datetime.datetime.now()
AttributeError: module 'datetime' has no attribute 'now'

Advertisement

Answer

As you named your file datetime.py it may lead to confusion when calling it from outside.

you should rename it to something else like my_datetime.py

you also need to import datetime before using it

import datetime
datetime.datetime.now()
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement