Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'datetime' has no attribute 'time' [duplicate]

I am using Python 3.7 and trying to learn datetime module from library, but I am getting AttributeError. code below:

import datetime

t = datetime.time(4, 20, 1)

# Let's show the different components
print(t)
print('hour  :', t.hour)
print('minute:', t.minute)
print('second:', t.second)
print('microsecond:', t.microsecond)
print('tzinfo:', t.tzinfo)

As run file I get this error AttributeError: module 'datetime' has no attribute 'time'

Please Help me to find where I am going wrong. Thanks

like image 821
Amjad Avatar asked Jun 25 '26 17:06

Amjad


1 Answers

The problem may be that your python file has the same name as the datetime module, maybe you called your program file datetime.py.

You need to rename your program file and delete any eventual .pyc file generated in your path, then you can import the correct datetime module.

like image 100
m.rp Avatar answered Jun 27 '26 12:06

m.rp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!