Leading 0's syntax error in datetime.date module (Python 3.6)

AK akarpierz at gmail.com
Thu May 10 07:39:27 EDT 2018


On 2018年05月10日 12:43, Virgil Stokes wrote:
> Module info:
>> Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 
> bit (AMD64)]
[...]
> I tried first to use Python's built-in datetime module as follows:
>> from datetime import date, timedelta
>>  d0 = date(2018,02,01)
>> This gave the following error:
>> Syntax Error: invalid token: C:\Users\Virgil Stokes\Desktop\Important 
> Notes_Files\CheckProcessingDate_02.py, line 7, pos 17
> d0 = date(2018,02,01)
>> Then I used pip to install the datetime module and the same error 
> occurred! However, when I removed the leading 0's no syntax error was 
> reported and the correct result was returned.

It is not a datetime problem. It is PY3 compatibility problem.
Try (should work from both PY2 and PY3):
d0 = date(2018,0o2,0o1)
AK


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /