Simple Python Project Structure
george.sakkis at gmail.com
Sat Oct 11 06:20:04 CEST 2008
On Oct 10, 9:26 pm, jay graves <jaywgra... at gmail.com> wrote:
> On Oct 10, 7:17 pm, amit <amit.ut... at gmail.com> wrote:
> > How do create my own modules and import them? Right now it works but
> > they all have to be in the same directory. For example,
> > project/
> > ....util/
> > ....config/
> > ....tests/
> > ....start.py
> You need an __init__.py file (it doesn't matter if it's empty) in the
> directory to turn it into a package.
I'm wondering if this is one of the few cases where Python's choice to
be explicit causes more trouble than it's worth. The official
The __init__.py files are required to make Python treat the
directories as containing packages; this is done to prevent
directories with a common name, such as "string", from unintentionally
hiding valid modules that occur later on the module search path.
Is this a real problem or a speculation ? I would guess that it's at
least as likely for a newbie to create a "string.py" module than have
an irrelevant "string" subdirectory under a code directory tree.
Having to create an empty file as a flag to denote a package doesn't
seem very pythonic.
More information about the Python-list