Number format; newbie makes deep heartfelt whinge

Dale Strickland-Clark dale at riverhall.NOTHANKS.co.uk
Tue Feb 18 04:49:22 EST 2003


Gary Duncan <gmduncan at netspace.net.au> wrote:

>
>The subject could just have been "inadequate Python diagnostic", or worse language.
>
>I've been hacking a bit of Python code to create a list of tuples,
>each tuple being a numeric pair of start_date,end-date, extracted
>as ASCII strings from a file.
>
>I kept getting "SyntaxError: invalid token" diagnostics when
>I ran the program, on certain tuples.
>
>Being a newbie, I interpreted this to mean some sort of formatting error
>(too many spaces?, comma in wrong place, naughty TAB somewhere , etc)
>
>The crux of the problem, as I belatedly discovered, was because each number
>had leading zeroes and were being interpreted as OCTAL numbers, and the
>diagnostic was occuring on the first number with a digit >7.
>
>I've always felt that the C-convention of attempting to convert a number
>with a leading 0 to octal was one of the few stupidities that K & R could
>be accused of . Too bad that Python has to be locked into it via its
>dependency on the underlying C-libs.
>
>Anyway, I would urge that a better diagnostic be written in this case.
>Wouldn't be surprised if there were large numbers of cases in Python
>where this vague and useless diagnostic was returned to puzzle and frustrate.
>
>(Timbot: I'd like to provide code fixes but I'm going to be too busy in
>  the foreseeable future in surveying the results of the recent horrendous
>  bushfires DownUnder. No doubt you and other US Pythonistas are also busy
>  with snow shovels, and lining your plush mansions with plastic sheeting
>  and duct tape  :->
>
>
>- Gary (who can't resist ending with a bit of final sarcasm, albeit mild)
>

I would guess you're using eval() and would suggest you try an
alternative approach. Posting code would have helped.
--
Dale Strickland-Clark
Riverhall Systems Ltd




More information about the Python-list mailing list