importing a module from a specific directory
orsenthil at users.sourceforge.net
Sun Jul 22 14:03:43 CEST 2007
> I would like to organize them into directory structure in
> which there is a 'main' directory, and under it directories for
> specific sub-tasks, or sub-experiments, I'm running (let's call them
> 'A', 'B', 'C').
> Is there a neat clean way of achieving the code organization?
This is a kind of a frequently asked question at c.l.p and every programmer I
guess has to go through this problem.
If you look around c.l.p you will find that one of the good ways to solve this
problem with the python interpretor <2.5 is:
>>> import sys
But, if you are using Python 2.5, you are saved.
Straight from the documentation:
Starting with Python 2.5, in addition to the implicit relative imports
described above, you can write explicit relative imports with the from module
import name form of import statement. These explicit relative imports use
leading dots to indicate the current and parent packages involved in the
relative import. From the surround module for example, you might use:
from . import echo
from .. import Formats
from ..Filters import equalizer
More information about the Python-list