Borg Pattern Class usable from other classes?

Erik Max Francis max at alcyone.com
Thu Oct 11 14:10:47 EDT 2001


Jan Wender wrote:

> 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?

The problem is you have a recursive import going there.  a imports b,
but b imports a.  That necessarily means that one of them won't get what
he expects.

The sequence appears strange anyway.  a.py defines the support classes
and b.py defines the test harness, but the __main__ clause of a.py
invokes the test harness?  Why not put the test harness where it
belongs, in b.py with the Test class?  That will eliminate your
recursive import problem.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ We are victims of our circumstance.
\__/ Sade Adu
    Alcyone Systems' CatCam / http://www.catcam.com/
 What do your pets do all day while you're at work?  Find out.



More information about the Python-list mailing list