saved sys.path

Eric S. Johansson esj at harvee.org
Tue Nov 2 18:57:25 EST 2004


Peter Hansen wrote:
> Most questions relating to this which haven't already been answered
> by Alex can be answered by a perusal of the site.py source.  It
> makes good readin'...

I'm sure it does and I will spend some bedtime reading (after I finish 
"lost in translation", an extremely good book that only shares the title 
with a movie.  I also recommend tsil cafe.)

> Note that between PYTHONPATH and .pth files, possibly the addition
> of a little sitecustomize.py file (see again site.py), and the
> ability to modify sys.path in the __main__ module of the app as
> Alex suggests, you can do pretty much anything you think is a good
> thing to do.

obviously, I need to grok site.py more.  But as a basic philosophical 
basis, I really believe that configuration information should be 
externalized from the program as much as humanly possible.  So things 
like modifying sys.path in __main__ is a source of maintenance problems 
further down the road.  the way I've been able to encapsulate the 
changes in my demonstration code and separate configuration file treats 
for me an environment which is much more predictable and reliable.

Another example is what I've done with configuration files in the camram 
project.  I created a configuration file module which uses three files 
to build a single view of configuration data.  At the base is the 
distribution default configuration elements.  Overlaid on that is the 
site configuration file data and last overlaid is the user specific 
configuration file data.  End result is that one I upgrade the system, I 
never ever need to touch the configuration file unless I'm modifying a 
new default.

Another thing I did in order to keep myself from making lots of mistakes 
is that I prefaced every string in the configuration file with a type 
information and as a result when the configuration file variable is 
returned, is always returned in the right form.  In addition to the 
normal string, integer, floats, I've also created paths so that file 
names will be automatically converted to the right form for that host.

I guess this is a long-winded way of saying that I try to create 
environmental support to keep me from making mistakes in my code.  I 
forget things, I use speech recognition and have to deal with 
recognition errors in addition to thinking about code or writing.  It's 
a helluva lot of cognitive effort so if I can make my code and modules 
work for me and catch my mistakes automatically, then it's a win.

but I will take your advice to heart.  Thank you for giving it.

---eric




More information about the Python-list mailing list