Possible Duplicate:
Is it possible to change the Environment of a parent process in python?
I am using python 2.4.3. I tried to set my http_proxy variable. Please see the below example and please let me know what is wrong. the variable is set according to python, however when i get out of the interactive mode. The http_proxy variable is still not set. I have tried it in a script and also tried it with other variables but i get the same result. No variable is actually set up in the OS.
Python 2.4.3 (#1, May 1 2012, 13:52:57)
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['http_proxy']="abcd"
>>> os.system("echo $http_proxy")
abcd
0
>>> print os.environ['http_proxy']
abcd
>>>
user@host~$ echo $http_proxy
user@host~$
When you run this code, you set the environment variables, its working scope is only within the process. After you exit (exit the interactive mode of python), these environment will be disappear.
As your code "os.system("echo $http_proxy")" indicates, if you want to use these environment variables, you need run external program within the process. These variables will be transfer into the child processes and can be used by them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With