circular import Module

Greg Ewing greg at cosc.canterbury.ac.nz
Wed Jun 8 22:43:53 EDT 2005


Thomas Guettler wrote:

> file1.py:
> import file2
> ....
> 
> file2.py:
> # import file1 # Does not work!

Actually, that *will* work as long as you don't
try to use anything from file1 until it has finished
being loaded.

What won't work is

   file2.py:
   from file1 import somename

because somename won't yet have been defined in
file1 at the time file2 is imported.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list