Module/package hierarchy and its separation from file structure
gagsl-py2 at yahoo.com.ar
Fri Jan 25 23:03:55 CET 2008
En Thu, 24 Jan 2008 11:57:49 -0200, Peter Schuller
<peter.schuller at infidyne.com> 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. Monkey.py and Tiger.py would be
>> inside that directory, just like Monkey.java and Tiger.java. Aren't the
>> same thing?
> No, because in Java Monkey.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/__init__.py. Neither option is what I would want, ideally.
You can also put, in animal/__init__.py:
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
More information about the Python-list