Why is this Python Borg / Singleton pattern working
问题 i just stumbled around the net and found these interesting code snipped: http://code.activestate.com/recipes/66531/ class Borg: __shared_state = {} def __init__(self): self.__dict__ = self.__shared_state # and whatever else you want in your class -- that's all! I understand what a singleton is but i don't understand that particular code snipped. Could you explain me how/where "__shared_state" is even changed at all? I tried it in ipython: In [1]: class Borg: ...: __shared_state = {} ...: def