Import question

Lonnie Princehouse finite.automaton at gmail.com
Tue Aug 9 15:21:59 EDT 2005


Circular import issues can usually be resolved by moving import
statements into the bodies of functions which aren't executed when the
module itself is imported.  Simple example:

---- fileA.py ------

import fileB as fb
foo = 10    # we're going to access foo from fileB

fb.do_something_with_foo()

---- fileB.py ------

def do_something_with_foo():
   import fileA as fa  # import is INSIDE the function
   print "foo is ", fa.foo

----------------------




More information about the Python-list mailing list