__dict__ attribute for built-in types

candide candide at free.invalid
Thu Oct 27 18:52:40 EDT 2011


Le 28/10/2011 00:19, Steven D'Aprano a écrit :
>> What, you think it goes against the laws of physics that nobody thought
> to mention it in the docs?<wink>

No but I'm expecting from Python documentation to mention the laws of 
Python ...
>>> But beside this, how to recognise classes whose object doesn't have a
>> __dict__ attribute ?
>> The same way as you would test for any other attribute.
>>>>> hasattr(42, '__dict__')
> False
>>
OK but I'm talking about classes, not instances : 42 has no __dict__ 
attribute but, may be, 43 _has_ such attribute, who knows in advance ? ;)
Let'have a try :
 >>> hasattr(43, '__dict__')
False
 >>>
so we have proved by induction that no integer instance has a 
dictionnary attribute ;)


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /