problems with circular references

John Roth johnroth at ameritech.net
Thu Mar 28 13:07:54 EST 2002


"jimh" <jim at jim.jim> wrote in message
news:a7tbd4$qc7$1 at web1.cup.hp.com...
> I am working on python code that consist of quite a few files (about
50;
> each file contains one class).  All errors returned by functions are
numeric
> and are defined in the individual files.  There is a MessageCatalog.py
class
> which will map these numbers into strings.  This MessageCatalog.py has
to
> import all of the 50 other files to have access to their error
numbers.  So
> far, so good - no problems yet.
>
> 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.
>
> Does anyone have ideas on how to deal with this situation?
>
> Thanks,
> Jim

I had that (almost) exact same problem, but with commands
commands instead of messages, and I didn't want to couple
the command modules with a central dictionary. In fact, I
wanted the entire thing to be highly modular: load the commands
you wanted, and just those commands.

What I wound up doing is putting the part of the command
dictionary in needed by a module in that module, and putting
a small routine at the end to copy it into the main driver/parser
module. This worked well. The loop still exists at run time,
but it doesn't exist at load time, so there isn't any module.

It might be slightly cleaner to register the commands in a
special purpose module that doesn't have any other function.
Then it's down at the bottom of the tree, and can't cause
any load time loops. Oh, well. Add it to the refactoring list...

John Roth
>
>





More information about the Python-list mailing list