problems with circular references

Gordon McMillan gmcm at hypernet.com
Thu Mar 28 08:24:00 EST 2002


jimh wrote:

> Here is the problem: Most of these 50 classes need to use the
> MessageCatalog themselves.  This means, of course, that classA imports
> MessageCatalog which imports classA.  This doesn't work very well.

As long as MessageCatalog uses a plain "import ...", this
should work fine. The import that completes the circuit
can't use "from ... import ...", because symbols inside
the module aren't available until all the imports complete.

You can often use delayed imports (imports inside function
or method bodies) to break the circularity, too.

-- Gordon
http://www.mcmillan-inc.com/



More information about the Python-list mailing list