circular import Module

Josef Meile jmeile at hotmail.com
Wed Jun 8 12:12:08 EDT 2005


>>Circular import does not work on module level, but you can
>>import the module in a method:
>>
>>file1.py:
>>import file2
>>....
>>
>>
>>file2.py:
>># import file1 # Does not work!
>>def foo():
>>    import file1 # Does work
> 
> 
> Cool idea !
> 
> It works on local namespaces, wich dont cause trouble to the whole program.
> 
> +1
Yes, I also think is a good solution. Once I needed to do something like
that and ended by writting a third module with the shared functions that
the two conflicting modules needed. At that time I already knew that one
could import modules from functions; however, I didn't come up with that
solution :-(

Regards,
Josef




More information about the Python-list mailing list