[Chicago] Python head-scratcher

Nick Timkovich prometheus235 at gmail.com
Sun Mar 29 17:34:17 CEST 2015


Note that in Python 3, the first date would also cause a SyntaxError. Octal
literals must start with "0o" just like hex ("0x") and binary ("0b").

On Sat, Mar 28, 2015 at 1:55 AM, Lewit, Douglas <d-lewit at neiu.edu> wrote:

> Thanks Robert.  I haven't played around with octal numbers in a while.
> This was interesting.  Thanks for sharing.
>
> On Fri, Mar 27, 2015 at 7:43 PM, Robare, Phillip (Randstant) <
> proba at allstate.com> wrote:
>
>> 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
>>
>>
>> _______________________________________________
>> Chicago mailing list
>> Chicago at python.org
>> https://mail.python.org/mailman/listinfo/chicago
>>
>
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20150329/8af0c1b4/attachment.html>


More information about the Chicago mailing list