How does Mr. Martelli's Borg recipe work ?

Mars martin_a_clausen at hotmail.com
Tue Jul 22 21:37:26 EDT 2003


I have looked long and hard at Mr. Martelli's Borg recipe:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531

It is a very useful substitute for a Singleton, but I can't figure out
how it works. _shared_state is never assigned any value, only
self.__dict__ is assigend self._shared_sate's value - or rather
(self.)_shared_state must be assigned a value at some point, otherwise
the code wouldn't work(right ?). I have gone through the code in the
debugger several(many) times, and inserted god knows how many print
statements, but without luck(or skill i guess).

Just so you don't waste your time, i do understand that _shared_state
is a class field(variable, or what not) and that its state is shared
by all instances.

Sorry if this question is banal, but I really need to understand this,
even if it means exposing my complete lack of understanding as far as
what is probaly basic Python knowledge.

Regards,

Martin




More information about the Python-list mailing list