Borg Pattern Class usable from other classes?

Jan Wender ian at atlas.science-computing.de
Thu Oct 11 09:29:15 EDT 2001


Jan Wender <j.wender at science-computing.de> wrote:
> Hi,
> I tried to use the Borg Pattern from Alex Martelli
> (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531). I have one file
> containing the Borg class. In another file I defined a second class which wants
> to access the information from the Borg class. It instantiates an object from
> the Borg class, but it seems that the class dictionary __shared_state gets newly
> initialized, rendering it empty. Any ideas to get it working? I tried already to
> use a module global dict in a.py, and also different access paths for the dict,
> to no avail.

It gets more confusing: If I add an accessor class to a.py:
class Test:
  def __init__(s):
     s.c = Borg()
  def acc(s):
     return s.c.t
and instantiate and call t.acc() from within a.py it works ok, but if I instantiate 
and call it from a class in b.py, I get an AttributeError as before.

Whats going on here?
Cheerio,
--
J.Wender at science-computing.de  -  Fon +4970719457-257 Fax-211
science+computing ag - Hagellocher Weg 71-75 - 72070 Tübingen
UNIX was not designed to stop you from doing stupid things, because that
would also stop you from doing clever things. (Doug Gwyn)



More information about the Python-list mailing list