organizing your scripts, with plenty of re-use

Steven D'Aprano steven at
Tue Oct 6 05:12:00 CEST 2009

On Mon, 05 Oct 2009 16:46:12 -0700, Carl Banks wrote:

> Notice the key idea in all of this: ONE script.  When you design it that
> a file can be used either as a script or as a module, you are asking for
> trouble.

I agree with everything you said in your post *except* that final 
comment. The basic idea of modules usable as scripts is a fine, reliable 
one, provided all the modules each script calls are visible in the 
PYTHONPATH. (You still have problems with recursive imports, but that can 
happen with any module, not just scripts.)

The Original Poster is confusing installation difficulties with code 
organization -- his problem is that users have special requirements for 
installation, and he's trying to work around those requirements by 
organizing his code differently.

As far as I can see, whether or not he uses a package, he will still have 
the same problem with installation, namely, that his users aren't 
developers, plus for non-technical reasons he can't provide an installer 
and has to have users check code out of CVS. Using a package will solve 
his internal code organization problems, and a simple setup script that 
modifies the user's .tcshrc to include the appropriate PYTHONPATH will 
solve his other problem. The solution is to work with the language, 
instead of fighting the language.


More information about the Python-list mailing list