[Chicago] Python head-scratcher
Robare, Phillip (Randstant)
proba at allstate.com
Sat Mar 28 01:43:13 CET 2015
The problem is that a leading zero on a number declares that string to be octal (base 8), and so only comprised of digits 1 to 7.
-----Original Message-----
From: Robare, Phillip (Randstant)
Sent: Friday, March 27, 2015 2:44 PM
To: 'The Chicago Python Users Group'
Subject: Python head-scratcher
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