__dict__ attribute for built-in types

Peter Pearson ppearson at nowhere.invalid
Fri Oct 28 11:52:49 EDT 2011


On Fri, 28 Oct 2011 00:52:40 +0200, candide <candide at free.invalid> wrote:
[snip]
>>>>> hasattr(42, '__dict__')
>> False
[snip]
>
> Let'have a try :
>
> >>> hasattr(43, '__dict__')
> False
> >>>
>
> so we have proved by induction that no integer instance has a 
> dictionnary attribute ;)

You left out an important step in this proof by induction.  Observe:

>>> n = 0
>>> hasattr(n, "__dict__")
False
>>> if hasattr(n, "__dict__") is False:
...   hasattr(n+1, "__dict__") is False
... 
True

There, now it's proven by induction.

-- 
To email me, substitute nowhere->spamcop, invalid->net.



More information about the Python-list mailing list