I was messing around with dynamic attributes and I noticed I could not use the __dict__ attribute if I created the object directly from the object() class but if I create a new class that is a direct descendent of object I can access the __dict__ attribute. Why the difference?
Examples:
# This gives an AttributeError o = object() o.__dict__
# This works: prints {}
class myClass(object):
pass
o = myClass()
o.__dict__
object
is implemented in C and doesn't have a __dict__
attribute. (Not all Python objects have it either; look up __slots__
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With