PYTHONPATH var

I

insfor

Hi guys. I have a question regarding runtime definition of the
variable PYTHONPATH. Do you know how without modifying of source code
change the value for this var. Value stores in the system var
sys.path, but the first item of this list, path[0], is the directory
containing the script that was used to invoke the Python interpreter.
We need to change this value which allows to us import scripts first
from directory containing newest hotfix scripts without replacing
original project scripts. One of the variant is to create script which
will modify this var and insert line with import this script into each
project script. So the question does another way exist? For example,
parameter or argument for python launcher.
 
S

Steven D'Aprano

Hi guys. I have a question regarding runtime definition of the variable
PYTHONPATH. Do you know how without modifying of source code change the
value for this var.

"Syntax error: sentence seems to be a question, but is missing a
question mark."

To answer your question, PYTHONPATH is an environment variable. You set
it in your shell. For example, I use the bash shell under Linux, and in
my .bashrc file I have this line:

export PYTHONPATH=/home/steve/python/

Every time I log in, the shell sets the environment variable to the
pathname /home/steve/python/, and then when Python runs, it appends that
path to sys.path. I don't have to modify any Python source code.


Value stores in the system var sys.path, but the
first item of this list, path[0], is the directory containing the script
that was used to invoke the Python interpreter. We need to change this
value which allows to us import scripts first from directory containing
newest hotfix scripts without replacing original project scripts. One of
the variant is to create script which will modify this var and insert
line with import this script into each project script. So the question
does another way exist? For example, parameter or argument for python
launcher.

I don't understand what you are actually trying to say here. Perhaps you
can explain a little bit more carefully?


However, trying to guess what you want, PYTHONPATH doesn't *replace*
sys.path, it appends to the end of it. This is usually the right thing to
do. However, sys.path is an ordinary list. If you want to modify it, you
can do so:

import sys
sys.path[0] = '/some/other/path'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top