Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41409 > unrolled thread

Re: How to add the current dir to sys.path when calling a python file?

Started byDave Angel <davea@davea.name>
First post2013-03-18 07:32 -0400
Last post2013-03-18 07:32 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

#41409 — Re: How to add the current dir to sys.path when calling a python file?

FromDave Angel <davea@davea.name>
Date2013-03-18 07:32 -0400
SubjectRe: How to add the current dir to sys.path when calling a python file?
Message-ID<mailman.3426.1363606369.2939.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web