circular imports

brian at mirror.org brian at mirror.org
Fri May 20 18:25:50 EDT 2005


> One feature I'm trying to fix is the use of:
> # how things are now
> sys.path.append('/general/path/aaa/bbb') # lots of lines like this to
> specific dirs
> import foo
>

I had a need to keep an python source for an application in separate
directories, but not as packages.  Rather that manually adjust sys.path
in every single module, I tried to centralize everything:

- config.py in main directory modified sys.path once, adding all the
directories I would need to sys.path.

- sitecustomize.py in every other directory, which did this:
    try:
        import config
    except ImportError:
        sys.path.append('/to/main/dir')
        import config
    (typed from memory, so hopefully no errors)

Hope that helps.
Brian.




More information about the Python-list mailing list