MarkyMarc wrote: > Hi All, > > I do not understand the packages system in python. I have read this > http://docs.python.org/tut/node8.html a 100 times and I can not get it > to work. > > I make a test app like this: > ******************************* > Test/ > __init__.py (a empty file) > apack/ > __init__.py (a empty file) > atest.py > bpack/ > __init__.py (a empty file) > btest.py > ******************************* > atest.py: > from Test.bpack import btest > > def printA(): > print "This is Atest from Apack" > > def printbtest(): > print btest.printB() > > print printA() > print printbtest() > ******************************* > btest.py: > from Test.apack import atest > > def printB(): > print "This is Btest from Bpack" > > def printatest(): > print atest.printA() > > print printatest() > ******************************* > > All I get is an import error: ImportError: cannot import name x > > I can remove the import statements an use the Test package quit normal > but when I try to make intra-pacage references I get the import error. > > I must be missing something, could any one point me at what. > > Thank you. > Would it hep to observe that the atest and btest submodules attemot to import each other?
There is no reason I can see for apack and bpack to be subpackages. Why not just rename atest.py as apack.py at the same level as the Test package's __init__.py, and in the same way make btest.py bpack.py. Then the __init__.py can do: from apack import printA from bpack import printB and your main program can do import Test Test.printA(...) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Sorry, the dog ate my .sigline so I couldn't cat it -- http://mail.python.org/mailman/listinfo/python-list