Basically I want to know why this works:
class MyClass:
pass
myObj = MyClass()
myObj.foo = 'a'
But this returns an AttributeError:
myObj = object()
myObj.foo = 'a'
How can I tell which classes I can use undefined attributes with and which I can’t?
Thanks.
You can set attributes on any class with a
__dict__, because that is where they are stored.objectinstances (which are weird) and any class that defines__slots__do not have one: