circular import snafu

Dirk-Ulrich Heise hei at adtranzsig.de
Thu Aug 10 03:03:28 EDT 2000


"Mookie D." <mookied at iname.com> schrieb im Newsbeitrag
news:8mtf4n$ujg$1 at nnrp1.deja.com...
> I have several modules that by necessity are including each other in a
> circular manner.

One of the common tricks to break up such cycles was, in C,
to use function vectors on the ground layer and set them up when the
app starts.

In Python, this would be something like:
Groundmodule.py:
  def Bla():
      pass

and later, in your top module, you'd do
  import Groundmodule
  def RealBla():
      DoSomethingMeaningFul()

  def Init_App():
      Groundmodule.Bla = RealBla
  Init_App()
  DoRealWork()
rebinding the references to the dummy function.
Not pretty, but it breaks up the cycle.
--
Dipl.Inform. Dirk-Ulrich Heise
hei at adtranzsig.de
dheise at debitel.net





More information about the Python-list mailing list