[Pythonmac-SIG] Using .pth to adjust Python on startup

Bob Ippolito bob at redivi.com
Fri Jan 14 19:47:13 CET 2005


On Jan 14, 2005, at 13:29, Robert White wrote:

> Last night, while researching a different problem, I ran across the 
> usage of 'import' within ".pth" to run arbitrary code as the Python 
> environment is being initialized.  I believe that this provides an 
> alternative to using PYTHONPATH and possibly some of the other 
> environment variables via  "~/.MacOSX/environment.plist".  Is this 
> correct?  If so, I will document it as such in the wiki.  Thanks for 
> your help.

.pth files *without* using the import statement are a replacement for 
PYTHONPATH.  These .pth files get processed every time that site.py 
runs, which happens for more cases than just the interactive prompt 
(i.e. it is not a replacement for .pythonrc).  The fact that they can 
use import statements is a cute trick, but shouldn't be used very often 
-- I only use it to make "deep" sys.path modifications when necessary, 
such as to override parts of the standard library.

-bob



More information about the Pythonmac-SIG mailing list