how to structure a directory with many scripts and shared code
jeanmichel at sequans.com
Mon Feb 15 17:06:49 CET 2010
Benedict Verheyen wrote:
> 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:
> 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:
> 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
1/ Provide the output of the error so we can provide some useful help.
2/ Embed your structure into a package. Names like 'tools', 'lib',
'mail', 'log' are too generic and will clash with other badly designed
module/package names. Choose a name for you package, and use it with
absolute imports e.g :
from myBeautifulPackage.tools.logutil import logger
3/ make sure your working copy of myBeautifulPackage is in your PYTHONPATH.
More information about the Python-list