I know this is a stupid question, but couldn't find an answer anywhere. I want to extract day and month separately into a variable and later on make few manipulations to them, but when I tried below code I keep getting a error. I tried to do the same thing in many different ways and it worked in shell, but doesn't work in my .py file.
from datetime import datetime
now = datetime.now()
print(now.month)
Error:
Traceback (most recent call last):
File "/home/john/Documents/Python/import time.py", line 1, in <module>
from datetime import datetime
File "/home/john/Documents/Python/datetime.py", line 3, in <module>
now = datetime.today()
AttributeError: 'module' object has no attribute 'today'
today()is a method fordatetime.dateinstead.from datetime import datetimeimported a different module from what you expected. Remove or rename the/home/john/Documents/Python/datetime.pyfile..import time.py; you may want to rename that too. :-)