Command-line option equiv of PYTHONPATH

R

Rajesh

Hi,

The '-I<path>' option adds the path to the list of directories that
contains modules that can be included in a script. I can use it as "#!/
usr/bin/perl -I<path_to_my_modules>" thereby not asking the user of
the script to set the <path_to_my_modules> in their environment.

Is there any equivalent command-line option to the python binary or a
command-line version of PYTHONPATH?

Regards
Rajesh
 
J

James Stroud

Rajesh said:
Hi,

The '-I<path>' option adds the path to the list of directories that
contains modules that can be included in a script. I can use it as "#!/
usr/bin/perl -I<path_to_my_modules>" thereby not asking the user of
the script to set the <path_to_my_modules> in their environment.

Is there any equivalent command-line option to the python binary or a
command-line version of PYTHONPATH?

Regards
Rajesh

Why not just modify sys.path within the actual script?

James
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

The '-I said:
contains modules that can be included in a script. I can use it as "#!/
usr/bin/perl -I<path_to_my_modules>" thereby not asking the user of
the script to set the <path_to_my_modules> in their environment.

Is there any equivalent command-line option to the python binary or a
command-line version of PYTHONPATH?

To rephrase James Stroud's remark: The equivalent to

#/usr/bin/perl -I<path_to_my_modules>
TEXT

is

#/usr/bin/python
import sys
sys.path.append(path_to_my_modules)
TEXT

HTH,
Martin
 
H

Harry George

Antoon Pardon said:
Maybe because he has multiple versions of modules he wants to test his
script against.


Here are some approaches we've used:

1. Write a small script which sets PYTHONPATH and then calls the app.
Make a different script for each setup you need.

2. Use a small script to set a couple of envvars, which in turn are
used to find the right config file, which has all the config
decisions you want.

archtool_path= os.getenv('ARCHTOOL_PATH')
archtool_cfg = os.getenv('ARCHTOOL_CFG')
sys.path.insert(0,archtool_path)
import archtool
exec "import archtool.%s as cfg" % archtool_cfg
 
?

=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=

Maybe because he has multiple versions of modules he wants to test his
script against.

See the original post: 'I can use it as "#!/usr/bin/perl
-I<path_to_my_modules>"' so clearly his intention is modify
the script.

Martin
 

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,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top