__dict__ strangeness
Georg Brandl
g.brandl-nospam at gmx.net
Sat Mar 18 10:04:06 EST 2006
Hi,
can someone please tell me that this is correct and why:
>>> class C(object):
... pass
...
>>> c = C()
>>> c.a = 1
>>> c.__dict__
{'a': 1}
>>> c.__dict__ = {}
>>> c.a
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'C' object has no attribute 'a'
>>>
>>> class D(object):
... __dict__ = {}
...
>>> d = D()
>>> d.a = 1
>>> d.__dict__
{}
>>> d.__dict__ = {}
>>> d.a
1
Thanks,
Georg
More information about the Python-list
mailing list