Packages

Bill Hale hale at tulane.edu
Thu Aug 10 21:05:26 EDT 2006


I have a question on packages.

Suppose I have a package P with modules A.py, B.py, and C.py.
Suppose that C.py defines a class X.
Assume that the package __init__.py file contains the statement
"from C import X".

If I write an external Python program H.py, then I can refer to
the class X by doing:

   import P
   myX = P.X()

My question is that I would like to use the same method for
consistentcy sake for the modules A and B in the package.
That is, if A needs to use the class X from C, I would like
to do the following in the file A.py:

   import P
   aX = P.X()

I tried this and it works. But, is there a problem with
recursion here since C might refer to A, or B might refer to
A and C refer to B? 

Is this even a good idea? Is there another way to achieve
the consistency whether referring to class X from an
external Python program or referring to class X from a
sibling Python program in the package?

Of course, the normal way to refer to class X in program A.py
is to do the following:

   from C import X
   aX = X()

Bill Hale



More information about the Python-list mailing list