os.putenv ?

Peter Hansen peter at engcorp.com
Wed Mar 26 18:49:35 CET 2003


Jacek Generowicz wrote:
> 
> > cat > grrr.py
> import os
> os.putenv("GRRR","This is a late parrot.")
> print "GRRR has been set to:", os.getenv("GRRR")
> > echo $GRRR
> 
> > python grrr.py
> GRRR has been set to: None
> > echo $GRRR

Processes generally can't affect the environment
of their parent process in this manner.  The environment
is a property of the shell, and you have to use the shell
to change it.  I believe one widely used technique for doing
this is to run the Python script from within a shell script
which will subsequently call out to another shell script
named, say, "modifyEnv.sh".  Then the Python script can 
just write the desired changes out to the modifyEnv.sh and
those changes will take effect when the Python script
terminates and the other script is run...




More information about the Python-list mailing list