[docs] python 2.7.6: Datetime issue

Tim Golden mail at timgolden.me.uk
Thu Jul 16 15:51:09 CEST 2015



On 15/07/2015 21:44, Tom Williams wrote:
> I am creating some test data by associating dates to certain fields.  I
> encountered the following issue:
> 
> 
> import datetime
> 
> myDate = datetime.date(2012,01,20) -- No issue
> 
> myDate = datetime.date(2012,02,20) -- No issue
> 
> myDate = datetime.date(2012,03,20) -- No issue
> 
> myDate = datetime.date(2012,04,20) -- No issue
> 
> myDate = datetime.date(2012,05,20) -- No issue
> 
> myDate = datetime.date(2012,06,20) -- No issue
> 
> myDate = datetime.date(2012,07,20) -- No issue
> 
> myDate = datetime.date(2012,08,20) -- SyntaxError: invalid token
> 
> myDate = datetime.date(2012,09,20) -- SyntaxError: invalid token
> 


I'm afraid you've been bitten by the slightly obscure fact that, in
Python, numbers which start with a zero are expected to be octal (base
8) and so any digit greater than 7 is invalid. This typically trips
people up who, like you, want to line numbers up and for whom the use of
base 8 for *anything* is pretty much unknown.

Sorry!

TJG


More information about the docs mailing list