how to structure a directory with many scripts and shared code

Benedict Verheyen benedict.verheyen at gmail.com
Mon Feb 15 10:29:05 EST 2010


Hi,

i wanted to ask how you guys structure your code.
I mainly have scripts that automate small tasks.
These scripts use a common set of utility code.
My code is structured like this, for example:

script_1.py
script_2.py
script_3.py
tools\
|----->__init__.py
|----->logutils.py
|----->mailutils.py

I was thinking of putting code in seperate directories because the number
of scripts grows fast and i want to keep it clean.
Something like this:

script_1.py
tools\
|----->__init__.py
|----->logutils.py
|----->mailutils.py
database\
|----->__init__.py
|----->script_2.py
|----->script_3.py

However, when i make a subdirectory, for example database and put a script in there,
how would i import logutils or mailtutils from within the database subdirectory?
This fails:
    from tools.logutils import logger

 Thanks,
 Benedict




More information about the Python-list mailing list