Meticulous. The two msg attributes are actually stored in two different dictionaries. One dwarfs the other, but the msg attribute, which goes astray, still takes up space in the dictionary. Thus, it is not used and still takes up some memory.
class MyClass(object): msg = 'FeeFiFoFum' def __init__(self, msg): self.msg = msg m=MyClass('Hi Lucy')
Please note that we have 'Hi Lucy' as the meaning.
print(m.__dict__)
Note that the MyClass dict (accessed via m.__class__ ) still has FeeFiFoFum .
print(m.__class__.__dict__) # {'__dict__': <attribute '__dict__' of 'MyClass' objects>, '__module__': '__main__', '__init__': <function __init__ at 0xb76ea1ec>, 'msg': 'FeeFiFoFum', 'some_dict': {}, '__weakref__': <attribute '__weakref__' of 'MyClass' objects>, '__doc__': 'my docstring', 'a_variable': None}
Another (possibly simpler) way to see this:
print(m.msg)
source share