"spir" <[email protected]> wrote
Can someone explain the following?
Not really an explanation but I did notice when repeating your experiment that your class instance has a __dict__ attribute but object does not. The new attribute a is apparently located in the dict.
class C(object): pass
...
['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash_ _', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr_o = object() c = C() c.a = 6 dir(c)
_', '__setattr__', '__str__', '__weakref__', 'a']
['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init_ _', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str_dir(o)
_']
print c.__dict__
{'a': 6}
And the dict exists before the new attribuite is created:
['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash_ _', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr_d = C() dir(d)
_', '__setattr__', '__str__', '__weakref__'] Does that help? I don't know.Why does a class inheriting from object acquire a dict when object doesn't have one?
I'm sure somebody can explain but its not me... Alan G. _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
