Possible Duplicate:
Why can't I directly add attributes to any python object?
Why can't you add attributes to object in python?
The following code does not throw AttributeError
class MyClass():
def __init__(self):
self.a = 'A'
self.b = 'B'
my_obj = MyClass()
my_obj.c = 'C'
That contrasts with
>>> {}.a = 'A'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'dict' object has no attribute 'a'
What makes such difference? Is it about dict being a built-in class while MyClass being user defined?