-3

Sorry if this is 'old hat', but I'd like to find the "proper" way to do this:

I have 2 python files, Foo.py and Bar.py such that

Foo.py calls FuncB() that's in Bar.py and Bar.py calls FuncF() that's in Foo.py.

If each file does an import of the other, won't this cause some kind of problem, or is the correct way of doing this using 'from Bar import FuncB'?

Steve76063
  • 317
  • 2
  • 10

1 Answers1

0

The following imports work fine, even though Foo and Bar import each other. This answer gets into more detail about why.

Foo.py

import Bar

def printFoo():
   print "Foo says hi"

def main():
    Bar.printBar()

if __name__ == "__main__":
    main()

Bar.py

import Foo

def printBar():
   print "Bar says hi"

def main():
    Foo.printFoo()

if __name__ == "__main__":
    main()
Community
  • 1
  • 1
merlin2011
  • 71,677
  • 44
  • 195
  • 329