How I fixed the AttributeError: type object 'datetime.datetime' has no attribute 'datetime' error
I'm learning Python and I was struggling with a problem related to converting time values from various formats to other formats. I kept getting the following error:
Traceback (most recent call last):
File "print 2.py", line 141, in <module>
Time = datetime.datetime.fromtimestamp(Time).strftime('%I:%M:%S %p')
AttributeError: type object 'datetime.datetime' has no attribute 'datetime'
For the life of me I could not figure out what was causing the error. Everything I read said that I was using the datetime function properly.
But what I found was the solution (and I'm sorry but I forgot where I read it) is that I needed to change the way I import the datetime module.
I was doing it like this:
from datetime import datetime
And all I had to do was erase that line and put the following line in instead:
import datetime
That was it. And now my program runs smoothly with no attribute errors.