how to structure a directory with many scripts and shared code
benedict.verheyen at gmail.com
Mon Feb 15 17:27:41 CET 2010
Jean-Michel Pichavant wrote:
> 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.
the error i get is this:
Traceback (most recent call last):
File "update_tax_responsible.py", line 18, in <module>
from tools.logutils import logger
ImportError: No module named tools.logutils
As to your comments on putting everything in a package, that's the whole problem,
it are all scripts where only a few of them are related and they all use
one or more modules that are located in the tools directory.
In that tools subdirectory i have a py file for typical file functions, time functions,
and so on. For instance, the tools\fileutils.py file contains amongst others
a function that calculates the size of a directory.
If i understood correctly, your suggestion is to put the utility files in
the tools subdirectory in a seperate package and put that package on the python path
so it can be shared by all scripts.
I should then further structure the scripts by putting scripts together.
But since the functions in tools are really utility functions for common tasks,
what would a meaningfule package name be?
The scripts are really diverse for instance, one of the scripts will
check the names of subdirectories made by employees, another will send mail
if people forget to fill in certain fields in a database and so on.
That's one of the reasons why i'm having a hard time structering it.
More information about the Python-list