os.environ conflicts with my shell
Michael Hudson
mwh21 at cam.ac.uk
Wed Mar 29 03:14:53 EST 2000
lewst <lewst at yahoo.com> writes:
> I'm having problems with os.environ conflicting with my shell when
> trying to set environment variables. I'll illustrate with an example.
> Take the following short Python program:
>
> #!/usr/bin/env python
> # start up an xterm with $NAME="John Q. Public"
> import os
> os.environ["NAME"] = "John Q. Public"
> os.system("xterm &")
>
> The trouble is that the environment in the new xterm still contains
> the old value of the $NAME environment variable. I'm guessing this is
> because $NAME is also set in my .zshrc which overwrites the value
> Python assigned to $NAME.
>
> How can I get the value of os.environ["NAME"] to stick in new xterm's
> environment?
Works here; what version of Python are you using? Try this instead:
>>> os.putenv("NAME","John Q. Public")
>>> os.system("xterm &")
But that shouldn't be necessary since Python 1.5.x (for some value of
x).
Cheers,
Michael
--
well, take it from an old hand: the only reason it would be easier
to program in C is that you can't easily express complex problems
in C, so you don't. -- Erik Naggum, comp.lang.lisp
More information about the Python-list
mailing list