saved sys.path

Alex Martelli aleaxit at yahoo.com
Mon Nov 1 15:13:49 EST 2004


Eric S. Johansson <esj at harvee.org> wrote:
   ...
> one of the things I've been bothered with using Python for larger 
> applications is path manipulation.  For example, how does one create the
> search path necessary to find your own modules if you do not wish 
> pollute site-packages with your private code.
> 
> the path file looks like this might be a good solution in preference to
> modifying sys.path in your code.  Are there any scope or limitation 
> rules for this path modifier?  Can this modification be made specific to
> an application or is the new path visible to the entire world (which 
> reintroduces the namespace pollution problem).

The modifications to sys.path performed by .pth files are visible to all
applications.  A single application may (however it chooses to do so)
find out or determine a path it wants only for its own imports, and
prepend it to sys.path, during its startup (entry-point script).  On
Windows the popular choice is to stick stuff in the registry; on most
Unix-like systems "run-command files" are usually preferred.  The Mac
(Mac OS X) has an extra possibility, since "an application" is a
directory (with extension .app) and the Mac has its own conventions
about what is where inside that directory.  Python is not particularly
different, from the point of view of "where does an app find its own
configuration information", from most other languages.


Alex



More information about the Python-list mailing list