Christopher J. Bottaro wrote:

Hello,
        I want to be able to say stuff like "import CJB.ClassA" and "import
CJB.ClassB" then say "c = CJB.ClassA()" or "c = CJB.ClassB()".  CJB will be
a directory containing files "ClassA.py" and "ClassB.py".

        Now that I think about it, that can't work because Python allows you 
import
different things from the same module (file).  If I said "import
CJB.ClassA", I'd have to instantiate ClassA like "c = CJB.ClassA.ClassA()".

I guess I could say "from CJB.ClassA import ClassA", but then I'd
instantiate like "c = ClassA()".  What I really want is to say "c =
CJB.ClassA()"...is that possible?

Is my understand of modules/packages correct or am I way off?

Thanks for the help.

Your understanding appears to be roughly correct, but you are overlooking the possibility that the package could manage its own namespace.

One thing you could try is, in the __init__.py for CJB, do

from ClassA import ClassA
from ClassB import ClassB

You can then refer to the classes using the names you want.

regards
 Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to