[Chicago] Python head-scratcher

Robare, Phillip (Randstant) proba at allstate.com
Fri Mar 27 20:43:31 CET 2015


I got an instant message this morning from a frustrated co-worker who was trying to get his unit tests to run.  He said that when he ran with a date of June 1 specified things went fine, but specifying August first gave him a syntax error.  The only change he was making was to change the "6" in the month field to an "8".  I was able to help him, but I thought those on this list might enjoy the puzzle.

>>> from datetime import date
>>> d = date(2014,06,01)
>>> print d
2014-06-01
>>> d = date(2014,08,01)
  File "<stdin>", line 1
    d = date(2014,08,01)
                   ^
SyntaxError: invalid token

(for those whose mail readers do not use fixed width fonts, the caret in the error is pointing at the 8.)

Clue:  A similar problem would exist in Java, C++, C and many others.

I will post the solution later today.

Phil Robare
probare at rcnchicago.com




More information about the Chicago mailing list