circular import Module

Philippe C. Martin philippe at philippecmartin.com
Wed Jun 8 18:33:49 CEST 2005


That's the only way out I found with some module import problem using code
generated by wxDesigner.


Josef Meile wrote:

>>>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