Setting environment for current shell

Donn Cave donn at u.washington.edu
Thu Jan 4 16:53:07 EST 2001


Quoth grante at visi.com (Grant Edwards):
| In article <932f4d$n0r$1 at nnrp1.deja.com>, bragib at my-deja.com wrote:
|
|> How do you set an environment for the shell you are running python in.
|> os.system() spawns its own shell.  I would like to gain access to the
|> parent shell.
|
| You can't.   You can only modify the current environment not
| your parent process's.

Right, and if you want to modify that current environment, the
"os" module exports an "environ" object that behave like a dict.

   import os
   os.environ['HI'] = 'Hi'
   os.system('printenv HI')

The same thing does not work with the posix module, though it has
a similar environ object;  there's extra stuff built into the os
version, that pushes changes into the environment propagated by
system() et al.

You can also supply a complete environment, as a dict, in the 3rd
parameter to posix.execve().

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list