Each invocation of os.system()
runs in its own subshell, with its own fresh environment:
>>> import os
>>> os.system("echo $$")
97678
0
>>> os.system("echo $$")
97679
0
You are unsetting the http_proxy
variable, but then your subshell has completed executing the command (to wit: unset
), and terminates. You then start a new subshell with a new environment in which to run echo
.
I believe what you are trying to do is del os.environ['http_proxy']
, or os.environ.pop('http_proxy')
if you want to ensure there is no http_proxy
environment variable whether or not one previously existed:
$ export foo=bar
$ python2
Python 2.7.10 (default, Jul 15 2017, 17:16:57)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['foo']
'bar'
>>> del os.environ['foo']
>>> os.system('echo $foo')
0