Unexpected behaviour of getattr(obj, __dict__)
Steven D'Aprano
steve at REMOVETHIScyber.com.au
Tue Feb 14 07:18:09 EST 2006
On Tue, 14 Feb 2006 13:03:17 +0100, bruno at modulix wrote:
> Steven D'Aprano wrote:
>> I came across this unexpected behaviour of getattr for new style classes.
>> Example:
>>
>>
>>>>>class Parrot(object):
>>
>> ... thing = [1,2,3]
>> ...
>>
>>>>>getattr(Parrot, "thing") is Parrot.thing
>>
>> True
>>
>>>>>getattr(Parrot, "__dict__") is Parrot.__dict__
>>
>> False
>
>
> hint:
>>>> getattr(object, '__dict__')
> <dictproxy object at 0x2aaaaab2ff30>
That doesn't answer the question, it just re-words it. Why is the
dictproxy returned by getattr a different instance from the dictproxy that
you get when you say object.__dict__?
--
Steven.
More information about the Python-list
mailing list