python - Error when calling datetime.date() -
i have 2 versions, both don't work reason can't tell.
first version
from datetime import datetime, date d = datetime.date(2011, 01, 01) print(d) which gives
file "timesince.py", line 3 d = datetime.date(2011, 01, 01) ^ syntaxerror: invalid token second version
from datetime import datetime, date d = datetime.date(2011, 1, 1) print(d) which gives
traceback (most recent call last): file "timesince.py", line 3, in <module> d = datetime.date(2011, 1, 1) typeerror: descriptor 'date' requires 'datetime.datetime' object received 'int' running python 3.3
you imported date datetime, work:
>>> d = date(2011, 1, 1) >>> d datetime.date(2011, 1, 1) no need put datetime infront
when import method module, no longer use name of module call method because imported specific method!
note:
your first instance invalid syntax because can't have 0 in beginning of integer in python. must use way: date(2011, 1, 1) , not way: date(2011, 01, 01)
Comments
Post a Comment