Module/package hierarchy and its separation from file structure

Gabriel Genellina gagsl-py2 at
Fri Jan 25 23:03:55 CET 2008

En Thu, 24 Jan 2008 11:57:49 -0200, Peter Schuller  
<peter.schuller at> escribió:

> In this case my
> problem is more related to the "file == module" and "directory ==
> module" semantics, since I want to break contents in a single module
> out into several files.

You already can do that, just import the public interfase of those several  
files onto the desired container module. See below for an example.

>> Isn't org.lib.animal a package, reflected as a directory on disk? That's
>> the same both for Java and Python. and would be  
>> modules
>> inside that directory, just like and Aren't the
>> same thing?
> No, because in Java is a class. So we have class Monkey in
> package org.lib.animal. In Python we would have class Monkey in module
> org.lib.animal.monkey, which is redundant and does not reflect the
> intended hierarchy. I have to either live with this, or put Monkey in
> .../animal/ Neither option is what I would want, ideally.

You can also put, in animal/
 from monkey import Monkey
and now you can refer to it as org.lib.animal.Monkey, but keep the  
implementation of Monkey class and all related stuff into  

Gabriel Genellina

More information about the Python-list mailing list