circular import Module

Thomas Guettler guettli at thomas-guettler.de
Wed Jun 8 10:44:11 EDT 2005


Am Wed, 08 Jun 2005 01:11:50 -0700 schrieb ajikoe at gmail.com:

> Hello,
> 
> I have two modules (file1.py and file2.py)
> Is that ok in python (without any weird implication) if my module
> import each other. I mean in module file1.py there exist command import
> file2 and in module file2.py there exist command import file1?
> 
> This is not working in C#.

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

HTH,
 Thomas

-- 
Thomas Güttler, http://www.thomas-guettler.de/





More information about the Python-list mailing list