Help me understand this

Gabriel Genellina gagsl-py at yahoo.com.ar
Tue Jan 30 18:39:28 CET 2007


En Tue, 30 Jan 2007 06:34:01 -0300, Beej <beej at beej.us> escribió:

> But here's one I still don't get:
>
>>>> type(2)
> <type 'int'>
>>>> type((2))
> <type 'int'>
>>>> (2).__add__(1)
> 3
>>>> 2.__add__(1)
>   File "<stdin>", line 1
>     2.__add__(1)
>             ^
> SyntaxError: invalid syntax

It appears to be a bug, either in the grammar implementation, or in the  
grammar documentation.
These are the relevant rules:

attributeref ::= primary "." identifier

primary ::= atom | attributeref | subscription | slicing | call

atom ::= identifier | literal | enclosure

literal ::= stringliteral | integer | longinteger | floatnumber |  
imagnumber

An integer is a primary so 2.__add(1) should be valid.

-- 
Gabriel Genellina




More information about the Python-list mailing list