Int methods (was RE: string.py)

Gerrit Holl gerrit.holl at pobox.com
Mon Feb 21 02:42:11 EST 2000


<quote name="Tim Peters" date="951065695">
<cut />
> > I see there might be parser problems, but maybe (5).radix? Python seems
> > willing to check for it:
> >
> > >>> a = (5).radix(2)
> > Traceback (innermost last):
> >   File "<stdin>", line 1, in ?
> > AttributeError: 'int' object has no attribute 'radix'
> 
> The parser has trouble with 5.radix because "maximal munch" lexing sucks up
> "5." as a float.

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

And:
>>> 1.(aaa)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: call of non-function (type float)

:)

> Note this cute one, though:
> 
> >>> 5..radix
> Traceback (innermost last):
>   File "<pyshell#1>", line 1, in ?
>     5..radix
> AttributeError: 'float' object has no attribute 'radix'
> >>>
> 
> That is, that's already parsed as (5.).float.
> 
> There's little reason to apply methods to numeric literals, though, and
> wrapping in parens is always sufficient.  Note too:
> 
> >>> (sys).stdin
> <PyShell.PyShell instance at 80b260>
> >>>
> 
> That may look strange at first, but the LHS of an attribute fetch can
> already be any expression whatsoever.
<cut />
</quote>

>>> (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

regards,
Gerrit.

-- 
Comparison Python GUI's: http://www.nl.linux.org/~gerrit/gui.html
Please comment!




More information about the Python-list mailing list