Ahmet Efe AKYAZI
Ahmet Efe AKYAZI

Reputation: 3

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'

Upvotes: 0

Views: 1246

Answers (2)

gxeia
gxeia

Reputation: 21

Try to change

import datetime

with

from datetime import datetime

credits: https://stackoverflow.com/a/19231474/12770606

Upvotes: 2

Lo&#239;c Baron
Lo&#239;c Baron

Reputation: 68

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()

Upvotes: 1

Related Questions