Hi am getting an error while trying a simple datetime import.
ImportError: No module named datetime
I am trying the following code in the git console.
>>> from datetime.datetime import strptime
I have tried re-installing python and it doesn't seem to work. What am I doing wrong?
datetime.datetime is a class datetime inside a module datetime. You can't import a method of a class, which is effectively what you are trying to do. Instead, you can:
from datetime import datetime
datetime.strptime(...)
or to "extract" the method the way you seem to want it:
strptime = datetime.strptime
though the name on the left side of the = is completely up to you.
The error message itself is coming from the second datetime in datetime.datetime, not the first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With