Setting environment variables.
Per Kistler
kistler at fnmail.com
Fri Aug 20 19:28:03 EDT 1999
Hi Thomas
I don't know UserDict yet, but it seems to work like that:
#!/per/bin/python
# Change env and mutate back to a shell
import os
shell = "/usr/bin/bash"
os.environ["MYVAR"] = "MYVALUE"
env = {}
for k,v in os.environ.items(): env[k] = v
os.execle( shell, "-", env )
Then I end up in a shell with the new environment:-)
Thanks a lot (, although it was not my original question)!
-Per.
Thomas Wouters wrote:
> >>> x = UserDict.UserDict(os.environ)
> >>> x["spam"] = "eggs"
>
> Just so you know i aint cheating this time ;-)
>
> >>> os.environ["spam"]
> Traceback (innermost last):
> File "<stdin>", line 1, in ?
> File "/usr/lib/python1.5/UserDict.py", line 14, in __getitem__
> def __getitem__(self, key): return self.data[key]
> KeyError: spam
>
> >>> os.execle("/bin/tcsh", "-", x)
> centurion:~/python > echo $spam
> eggs
>
> Yes, you could set os.environ before an os.exec*(), but passing a modified
> env is nicer.
>
> --
> Thomas Wouters <thomas at xs4all.net>
>
> Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
--
Per Kistler kistler at fnmail.com / kistler at gmx.net
------------------------------------------------------------
More information about the Python-list
mailing list