int literals and __class__

Alex Martelli aleaxit at yahoo.com
Tue Nov 16 02:14:16 EST 2004


Steven Bethard <steven.bethard at gmail.com> wrote:

> Dan Bishop <danb_83 <at> yahoo.com> writes:
> > You don't have to ask *that* nicely.
> > 
> > >>> 1 .__class__  # notice the space
> > <type 'int'>
> 
> Why does this work?  Or, perhaps my real question is why *doesn't* it work
> without the space?  Pointers to the appropriate point in the docs would be
> fine...  I assume it's something about making parsing easier...?

It's to make lexing more predictable: it's known as maximal-much lexing
(without backtracking: backtracking in lexical analysis would really but
really be bad).  '1.' (no space) is a token (stands for a float
literal).  So, '1.__class__' is two tokens: float '1.' followed by
identified '__class__'.


Alex



More information about the Python-list mailing list