[Tutor] datetime syntax error for May 8th and 9th 2008??

John Fouhy john at fouhy.net
Sat May 17 06:29:50 CEST 2008


On 17/05/2008, Che M <pine508 at hotmail.com> wrote:
> >>> datetime.datetime(2008, 05, 08)
> SyntaxError: invalid token

It's simpler than that... Try this:

>>> x = 08
  File "<stdin>", line 1
    x = 08
         ^
SyntaxError: invalid token
>>> x = 010
>>> x
8

Basically, python interprets integer literals starting with 0 as octal
numbers.  It's an old convention from C (or earlier?).  It doesn't
affect strings, so int('010') == 10 (unless you use eval).

HTH!

-- 
John.


More information about the Tutor mailing list