About __class__ of an int literal
Hans Mulder
hansmu at xs4all.nl
Tue Sep 28 16:08:44 EDT 2010
Tim Golden wrote:
> On 28/09/2010 10:27, AlexWalk wrote:
>> In python 3.1.2(I'm using windows edition, 32bit), accessing __class__
>> of an int literal will raise a SyntaxException, while other literals
>> will not. For example. 1.__class__ is an error, while 1.1.__class__
>> runs ok.
>>
>>
>> I searched the python issue tracker but failed to find relevant
>> reports. I wonder if this is an unreported issue.
>
> It's a little bit subtle. The trouble is that the parser
> sees a number followed by a dot and assumes that it's looking
> at a decimal number. When the next thing isn't a number, it
> raises a SyntaxError exception.
>
> You can achieve what you're after by putting a space before the dot:
>
> 1 .__class__
Alternatively, you can use parenthesis:
(1).__class__
Some people find one solution uglier than the other.
-- HansM
More information about the Python-list
mailing list