Error evaluating numbers starting in zero

Richard P. Muller rpm at wag.caltech.edu
Sun Dec 17 13:36:45 EST 2000


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