I have looked long and hard at Mr. Martelli's Borg recipe:
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_sa te'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
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_sa te'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
Comment