I was trying out dynamic attribute assignment for testing purposes and discovered following behavior:
>>> class Foo(object): pass
...
>>> bar = Spam()
>>> bar.a = 1
>>> spam = object()
>>> spam.a = 2
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'object' object has no attribute 'a'
Why is the first version with a derived class legit, but the second direct usage of object
not? It seems a bit strange to me because deriving hasn't changed anything that has obviously something to do with how variable assignment is handled.