Creating environment variables.
Fredrik Lundh
fredrik at pythonware.com
Wed Aug 27 05:23:35 EDT 2008
aditya shukla wrote:
> I am writing a program(prog 1) in python , which requires to know the
> path of another program(prog 2) in order to execute.I can get my prog1
> to work when i hard code the path of the existing program(prog2).But
> since the path of prog could be anywhere on the file system , thus i
> cannot hard codes its path.And i am not supposed to take the path of
> prog2 as an input to prog1.So is there anyway to solve this problem , by
> the creation of environment variable (whose value is set as the path of
> prog 2)?
just set the variable before you start prog1, and use os.environ to read it:
path = os.environ["MYVARIABLE"]
> Also how do i create environment variable for prog1?
that depends on what platform (and shell) you're using. on Windows, you
can set environment variables via the SET command, or, permanently, via
the control panel (System -> Advanced -> Environment Variables). on
Unix, use "export" (for bash-style shells) or "setenv" (for csh-style
shells). to set them permanently, add the appropriate commands to your
startup/profile scripts.
</F>
More information about the Python-list
mailing list