REPOST: Re: module path

Alex Martelli aleax at aleax.it
Fri Dec 28 07:03:03 EST 2001


"Garett Shulman" <shulmang at colorado.edu> wrote in message
news:n1an2u4rvau9f86r5dcl895lokb05354pr at 4ax.com...
> I would like to store my modules and scripts in a folder other than
> the python folder. Does anyone have any suggestions as to what I need
> to do in order to be able to import the scipts in the interpreter? Is
> there a path that the interpreter searches which I could modify?

Yes, and that path is a list, named 'path', in standard module 'sys'.

You can do, for example:
    import sys
    sys.path[0:0] = '/my/directory'
and on successive imports, "/my/directory" will be tried before other
directories on sys.path.

There are also more permanent ways to alter sys.path.  The handiest
one is to put a textfile, any name, extension .pth, in the Python
directory (the site-packages one, under Linux; just C:\Python22,
under Windows).  yourfile.pth can list any number of directories,
one per line; they will all be added to sys.path during startup
(by module site.py).  This makes your directories be appended AFTER
others in the path, though.  You can also define environment variable
PYTHONPATH, or, on Windows, hack the registry.


Alex

========= WAS CANCELLED BY =======:
Path: news.sol.net!spool0-nwblwi.newsops.execpc.com!newsfeeds.sol.net!newspump.sol.net!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!sjc1.nntp.concentric.net!newsfeed.concentric.net!newsfeed.ozemail.com.au!ozemail.com.au!not-for-mail
Message-ID: <cancel.a0hn1l$lbd$1 at serv1.iunet.it>
Control: cancel <a0hn1l$lbd$1 at serv1.iunet.it>
Subject: cmsg cancel <a0hn1l$lbd$1 at serv1.iunet.it>
From: "Alex Martelli" <aleax at aleax.it>
Newsgroups: comp.lang.python
X-No-Archive: yes
Lines: 2
NNTP-Posting-Host: wonenara.ozemail.com.au
X-Trace: ozemail.com.au 1009643033 203.108.164.177 (Sun, 30 Dec 2001 03:23:53 EST)
NNTP-Posting-Date: Sun, 30 Dec 2001 03:23:53 EST
Organization: OzEmail Ltd, Australia
Distribution: world
Date: Sat, 29 Dec 2001 13:25:39 GMT

This message was cancelled from within Mozilla.



More information about the Python-list mailing list