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


Groups > comp.lang.python > #41409

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

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'skip:[ 20': 0.03; 'argument': 0.04; 'modify': 0.05; 'sys': 0.05; 'so?': 0.07; 'subject:file': 0.07; 'variable,': 0.07; 'subject:How': 0.09; 'python': 0.09; '"if': 0.09; 'given,': 0.09; 'inserted': 0.09; 'path.': 0.09; 'subject:python': 0.11; "skip:' 30": 0.15; 'is",': 0.16; 'subject: \n ': 0.16; 'subject:when': 0.16; 'sys.path': 0.16; 'variable.': 0.16; 'wrote:': 0.17; 'script.': 0.17; 'variable': 0.20; 'trying': 0.21; 'import': 0.21; 'location,': 0.22; 'script': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'environment': 0.29; 'cat': 0.29; "skip:' 20": 0.32; 'running': 0.32; 'print': 0.32; 'says': 0.33; 'directory,': 0.33; 'to:addr:python-list': 0.33; 'front': 0.33; 'hi,': 0.33; 'text': 0.34; 'path': 0.35; 'pm,': 0.35; 'subject:?': 0.35; 'there': 0.35; 'anything': 0.36; 'subject:: ': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'containing': 0.61; 'different': 0.63; 'within': 0.64; 'received:74.208': 0.71; '.....': 0.75; 'subject:add': 0.91
Date Mon, 18 Mar 2013 07:32:28 -0400
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130221 Thunderbird/17.0.3
MIME-Version 1.0
To python-list@python.org
Subject Re: How to add the current dir to sys.path when calling a python file?
References <CABrM6wkErdLMGcZ1PinhPbW4qWtxuCXC1kkQAvswm3FKvzpY8w@mail.gmail.com>
In-Reply-To <CABrM6wkErdLMGcZ1PinhPbW4qWtxuCXC1kkQAvswm3FKvzpY8w@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:BQ9QNoe4oOhvL3uyB3pardpss8E6Fgf5W6RjL7fvM7+ jD+NkELt0rOFx5X0V5bJeuJ27udQOIdCFuewI6vqi40BKfCL9P YMLxHN6bPEQh2+Shp+4h8KlzmIb52rYeP6muJ1aKUX2knccZmc kV+ZnI2vxxWP1nI8dVrkppROJZ/llkf6xe6HAIj9ar0IKCKbcm 9YrxSqh8Mfvh1yXGOZ6kPxxZCgZkmjgOeuzmOfDUVMGpvw7GgI DAfHazHEzo1EPgusrSg5uidNSXdI2R0RTTJ7Z3hgNgE9aGequa 48IZ7CWuCaKwWEcZ8OtIjvQep8Fb6Ljas3uaeTpXPmV5B/AJA= =
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3426.1363606369.2939.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1363606369 news.xs4all.nl 6937 [2001:888:2000:d::a6]:38180
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:41409

Show key headers only | View raw


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


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