[Python-Dev] Int literals and method calls

"Martin v. Löwis" martin at v.loewis.de
Sun Nov 14 22:30:49 CET 2004


Kay Schluehr wrote:

>  >>> 1.__class__
> Traceback (  File "<interactive input>", line 1
>    1.__class__
>              ^
> SyntaxError: invalid syntax
> 
> So it seems to be a parser-problem, related to the ambiguity of the 
> terminating dot?

There is no ambiguity. This expression parses as two tokens,
floatnumber (through the second alternative of pointfloat),
followed by identifier. While this is not explicitly specified
in the language reference, Python follows the common "longest
match" approach to tokenization, i.e. you extend each token
from the beginning of the input as much as you can, and then
proceed to the next token.

> Could this be patched?

Perhaps. But it should not, as the current behaviour is
intentional. If you want to take attributeref of an
integer literal, use one of the following forms:

 >>> 2 .__class__
<type 'int'>
 >>> (3).__class__
<type 'int'>

Regards,
Martin


More information about the Python-Dev mailing list