software design question

Josiah Carlson jcarlson at nospam.uci.edu
Sat Feb 7 20:27:36 CET 2004


> I have the following inter-class relationships:
> 
> __main__:  (in file LMCMain.py)
>   imports module FileIO
>   defines class LMCMain 
>   instanciats main = LMCMain(...)
> 
> FileIO.py:
>   defines class FileIO
>   class FileIO needs to access "main" from LMCMain.py

I don't know what one /should/ call it, but what you have is what I 
would call a circular import.  You are attempting to have two modules 
use the internals of each other.  That is poor design.

You can use a kludge to get past poor design by using the following:

main = LMCMain()
import sys
sys.modules['FileIO'].main = main


In the future, better design is suggested.

  - Josiah



More information about the Python-list mailing list