Numeric methods again

Guido van Rossum guido at python.org
Wed Jul 25 15:48:37 EDT 2001


"Magnus Lie Hetland" <mlh at idi.ntnu.no> writes:

> Now that Python seems to be getting numerig methods
> (like "5 .__add__" etc.) I'm pretty happy about that.
> But I find it odd that there has to be whitespace
> in front of the reference dot... For a simple parser
> it might be difficult to know whether 5. was a float
> or the beginning of a reference, but with a bit of
> lookahead that can't be too hard? Is there any way
> that 5._ is not the beginning of a reference to a
> numeric method? Can a number ever be directly followed
> by an identifier? Is the parser to weak to parse this
> stuff? Am I just being dense?
> 
> This definitely looks like a (little) wart to me...
> 
> (I'm sure I should RTFM here - but I've looked through
> the PEPs and haven't found this in there...)

This is the kind of wartlet that's hard to fix right (there could be
an arbitrary about of comments between the "5." and the "__add__") and
not a problem in practice.  You won't be writing "5 .__add__" in
practice -- you'll be writing "x.__add__", where x happens to contain
an integer.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-list mailing list