.pth files

Peter Hansen peter at engcorp.com
Tue Aug 9 07:52:29 EDT 2005


Neil Benn wrote:
>    * Site.py is prompted to load a sitecustomise.py file which is
>      located in the Lib directory - if it is there.  This file is
>      automatically executed on the start up of python.  Here you can
>      look for a command line argument (or a local config file) passed
>      in - you can then go and find the .pth file yourself.  The code to
>      pull in .pth stuff is located in the site.py file - you can import
>      this function and use it but I don't do that for two reasons
>      (instead I pull across my own copy - effectivly freezing that
>      implementation):
> 
>         1. You are creating a circular reference

The "import sitecustomize" stuff is placed effectively at the end of 
site.py, so it should be quite safe to "import site" from your 
sitecustomize.py file and use the functions there.

>         2. I can find no docs or imformation about using the functions
>            in the site.py file so therefore I have to assume that the
>            functions in the site.py file are not designed to be used
>            this way and therefore shouldn't be relied upon to be stable
>            or even present across python releases (I'm a conservative
>            programmer.

While I can't fault your caution, we've been using a few things in 
site.py from sitecustomize for a while with no problems (across releases 
from Python 1.5.2 to Python 2.4).  The functions are documented in the 
site.py source itself, of course, at least in a cursory fashion, and 
while there have been changes over versions, I don't recall anything 
causing breakage.  Normally I'd quite agree about staying away, but for 
something like this (i.e. not a core part of an application, but 
something to set up the environment instead) I'd say "go for it".

-Peter



More information about the Python-list mailing list