Question about circular imports

OKB (not okblacke) brenNOSPAMbarn at NObrenSPAMbarn.net
Sun Feb 26 20:57:49 CET 2012


Frank Millman wrote:

> The first solution is -
> 
> in wavread.py -
>     import formats.wavwrite
> 
> in wavwrite.py -
>     import formats.wavread
> 
> I then have to use the full path to reference any attribute inside
> the imported module, which I find cumbersome.

    	This isn't really true.  If this is the only thing you're worried 
about, you can always do the "manual" version of a "from X import Y":

import formats.wavread
wavread = formats.wavread

wavread.someFunc() # refers to functions in module formats.wavread.

    	Also, I'm too lazy to check right now, but I wouldn't be suprised 
if "mport formats.wavread as wavread" also works even in the circular 
case.

-- 
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
	--author unknown



More information about the Python-list mailing list