os.environ conflicts with my shell
mwh21 at cam.ac.uk
Wed Mar 29 12:30:58 CEST 2000
Michael Hudson <mwh21 at cam.ac.uk> writes:
> 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.
Doh, didn't read this the first time!
> > How can I get the value of os.environ["NAME"] to stick in new xterm's
> > environment?
try os.system("xterm -e zsh -f &"); this disables the reading of most
of the init files.
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