i just stumbled around the net and found these interesting code snipped:
http://code.activestate.com/recipes/66531/
class Borg:
__shared_state = {}
The __init__
method, which is called after instantiating any object, replaces the __dict__
attribute of the newly created object with the class attribute __shared_state
.
a.__dict__
, b.__dict__
and Borg._Borg__shared_state
are all the same object. Note that we have to add the implicit prefix _Borg
when accessing private attribute from outside the class.
In [89]: a.__dict__ is b.__dict__ is Borg._Borg__shared_state
Out[89]: True