int literals and __class__ (WAS: Is a list an instance of a class?)

Russell Blau russblau at hotmail.com
Tue Nov 16 09:09:08 EST 2004


"Steve Holden" <steve at holdenweb.com> wrote in message
news:_qmmd.10659$nj.4248 at lakeread01...
> Steven Bethard wrote:
>
> > Dan Bishop <danb_83 <at> yahoo.com> writes:
> >
> >>>>>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...?
> >
> Yup, it's because a dot immediately following an integer would be parsed
> (strictly "lexed", I suppose) as a floating point constant,m aking the
> __class__ a syntax error.
>
> regards
>   Steve

And, in case anyone was wondering (as I was), the following works, too,
despite the fact that it looks incredibly odd:

>>> print 1. .__class__
<type 'float'>

-- 
I don't actually read my hotmail account, but you can replace hotmail with
excite if you really want to reach me.





More information about the Python-list mailing list