Error evaluating numbers starting in zero
Bjorn Pettersen
pbjorn at uswest.net
Sun Dec 17 14:03:35 EST 2000
How about:
>>> time.strptime('01/08/99', '%m/%d/%y')
(1999, 1, 8, 0, 0, 0, 0, 0, 0)
or
>>> string.atoi('09')
9
or
>>> int('09')
9
-- bjorn
"Richard P. Muller" wrote:
> I'm sure people already know about this, but I just got hit with a
> really screwy error.
>
> I have a python checkbook program that evaluates date strings, such as
> "01/31/99". Most dates are fine, but if I have a date such as
> "01/08/99", python runs into an error when it tries to eval("08").
>
> I can see how this might be a feature and not a bug, in that it
> interprets numbers starting in "O" as octyl.
>
> My workaround is the function:
>
> def chop_leading_zeros(str):
> # removes a single leading zero from a string to be evaluated
> # I think it interprets these numbers as Octyl
> if str[0] == '0':
> str = str[1:]
> return str
>
> Does anyone have a simpler or more elegant workaround?
More information about the Python-list
mailing list