Question about circular imports

Frank Millman frank at
Sun Feb 26 06:18:20 EST 2012

"Frank Millman" <frank at> wrote in message 
news:jid2a9$n21$1 at
> Hi all
> I seem to have a recurring battle with circular imports, and I am trying 
> to nail it once and for all.
> The second solution is -
> in formats/
>    import sys
>    sys.path.insert(0, __path__[0])
> in -
>    import wavwrite
> in -
>    import wavread
> This works, but I don't know if it is a good idea to add all the 
> sub-package paths to sys.path. I realise that it is up to me to avoid any 
> name clashes. Are there any other downsides?

Answering my own question, I have just found a downside that is a 

If a module in a different sub-package needs to import one of these modules, 
it must use a full path. This results in a new entry in sys.modules, and 
therefore any attributes referenced by the intra-package module have 
different identities from those referenced from outside. If they are static, 
there is no problem, but if not, disaster strikes!


More information about the Python-list mailing list