Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41409
| Date | 2013-03-18 07:32 -0400 |
|---|---|
| From | Dave Angel <davea@davea.name> |
| Subject | Re: How to add the current dir to sys.path when calling a python file? |
| References | <CABrM6wkErdLMGcZ1PinhPbW4qWtxuCXC1kkQAvswm3FKvzpY8w@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3426.1363606369.2939.python-list@python.org> (permalink) |
On 03/17/2013 11:56 PM, Peng Yu wrote: > Hi, > > man python says "If a script argument is given, the directory > containing the script is inserted in the path in front of $PYTHONPATH. > The search path can be manipulated from within a Python program as > the variable sys.path." Instead I want to have the current directory > inserted to the front of $PYTHONPATH without changing anything the > script. Is there a way to do so? > if the script you're running is in the current directory, it'll just already do what you seem to be asking. cd /home/davea/temppython cat peng.;py import sys print "sys.path is", sys.path python peng.py sys.path is ['/home/davea/temppython', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/l ..... The text you quoted is trying to say that there are 3 different ways you can modify the search path. The script name's location, the $PYTHONPATH environment variable, and the sys.path Python variable. -- DaveA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: How to add the current dir to sys.path when calling a python file? Dave Angel <davea@davea.name> - 2013-03-18 07:32 -0400
csiph-web