How to avoid mutual imports

Huaiyu Zhu huaiyu at gauss.almadan.ibm.com
Fri Apr 12 16:45:22 EDT 2002


Brian Quinlan <brian at sweetapp.com> wrote:
>Huaiyu wrote:
>> I need advice on how to handle the following situation:
>
>[long description snipped]
>
>If interface.py only defines data_initialization, then you could move
>your imports into it i.e.
>
>def data_initialization(...):
> 	from utils1 import a, b, c
> 	from utils2 import x, y, z
>
>	# do real work

This, plus a little rearrangement elsewhere, does the trick.  Thank you.

It is a little bit tedious, though, since the data_initialization is in fact
many separate functions, and the import has to be repeated.  The good thing
is that the imports are not all the same, so the new arrangement makes clear
where each one is needed.

>You could also move data_initialization into its own module (might be a
>good idea anyway).

Well, that has the same problem if I want to use the data in the testing,
unless testing is also in a separate module.

Huaiyu



More information about the Python-list mailing list