Int methods (was RE: string.py)

Tim Peters tim_one at email.msn.com
Mon Feb 21 19:37:58 EST 2000


[Tim]
>> ...
>> The parser has trouble with 5.radix because "maximal munch"
>> lexing sucks up "5." as a float.

[Gerrit Holl]
> I can't understand why this won't work, either:
> >>> aaa=4
> >>> 1.aaa
>   File "<stdin>", line 1
>     1.aaa
>         ^
> SyntaxError: invalid syntax

If you understood why 5.radix didn't work, you can't possibly not understand
why 1.aaa didn't work -- they're both of the form

    int_literal "." name

and the parses "sees that" as

    float_literal name

> >>> (1,2).aaa
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> AttributeError: 'tuple' object has no attribute 'aaa'
> >>> (1,2).(aaa)
>   File "<stdin>", line 1
>     (1,2).(aaa)
>           ^
> SyntaxError: invalid syntax

What about it?  The LHS (left hand side) of an attribute reference can be
any expression, but the RHS (right hand side) must be a name.  "(aaa)" isn't
a name, and the introduction of int methods doesn't require generalizing any
of these rules.






More information about the Python-list mailing list