[Tutor] Importing multiple files as a single module?

Max Noel maxnoel_fr at yahoo.fr
Fri Jan 21 17:33:15 CET 2005


Hi everyone,

	Having learnt OOP with C++, and most of my OOP experience being with 
Java, I'm used to storing my classes in one file for each class. I find 
it tidier and easier to read/debug.
	However, when I try to do the same in Python, each file corresponds to 
a module with a single class in it.

	Is there a way to obtain the same result in Python as in Java? That 
is, I'd like to have the following on my hard drive:

foo/
	Bar.py
	Baz.py

	Where Bar.py and Baz.py each contain a single class (Bar and Baz). 
Then, from Python, I'd import the foo module (import foo) and then 
access the classes with foo.Bar and foo.Baz (instead of foo.Bar.Bar and 
foo.Baz.Baz, which is what I have now). Being able to use Bar in Baz.py 
would of course be a nice side effect.

	Any ideas? Or am I trying to do things in a very non-Pythonic way? If 
so, how am I supposed to organize my OOP code, especially given the 
absence of a "real" IDE for Python?

Thanks for your attention,
-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?"



More information about the Tutor mailing list