I cannot import datetime from a python script, but I can from the terminal command line.
1)import datetime
2)From datetime import datetime
month = datetime.datetime.now().strftime("%B")
print month
These lines of code work when entered one by one into the command line Any ideas?
I'm running 2.7 on mac
datetime' has no attribute 'datetime'. To resolve the problem, we just have to “import datetime” instead of “from datetime import datetime” as we did it above.
datetime is a built-in Python module. Developers don't need to install it separately.
You named your script datetime.py
, located at /Users/ripple/Dropbox/Python/datetime.py
. This is being imported instead of the standard library module, because the directory of the main script is the first place Python looks for imports.
You cannot give your scripts the same name as a module you are trying to import. Rename your script. Make sure you also delete the bytecode cache at /Users/ripple/Dropbox/Python/datetime.pyc
.
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