Python-list Digest, Vol 35, Issue 160

skip at pobox.com skip at pobox.com
Thu Aug 10 09:41:45 EDT 2006


    Brendon> Seems that parsing negative numbers is outside of the scope of
    Brendon> this routine. Here's the source (which is Frederik's source
    Brendon> with one minor renaming; I take no credit here); anyone have
    Brendon> any ideas?

Negative numbers are actually tokenized as a MINUS followed by a NUMBER:

    % python
    Python 2.5b2 (trunk:50921, Jul 28 2006, 20:21:50) 
    [GCC 4.0.0 (Apple Computer, Inc. build 5026)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> - 47
    -47

Try changing your atom function to detect a minus sign, remember that fact,
then require the next token to be a number.

Skip



More information about the Python-list mailing list