Issue 1110478: os.environ.update doesn't work (original) (raw)
os.environ.update doesn't really update os.environ -- it doesn't call putenv subsequently.
This is the test code:
#test1.py import os FILENAME='test2.py' env={};env['ENVIRON_UPDATE']='123';os.environ.update(env) os.environ['ENVIRON_DIRECT_SETTING']='123' cmdline='c:\python24\python.exe -u %s'%FILENAME fs=os.popen3(cmdline,'b') print fs[1].read()
#test2.py import os if os.environ.has_key('ENVIRON_UPDATE'):print 'os.env.update worked' else:print 'os.env.update failed' if os.environ.has_key('ENVIRON_DIRECT_SETTING'):print 'os.env assignment worked' else:print 'os.env assignment failed'
Run test1.py with python 2.4 on windows.
The reason os.environ.update doesn't work is the update method is removed from 2.4. (It works with 2.3)
Following is the patch:
--- os.py Thu Jan 27 07:09:38 2005 +++ os_new.py Thu Jan 27 07:10:44 2005 @@ -435,6 +435,9 @@ return key.upper() in self.data def get(self, key, failobj=None): return self.data.get(key.upper(), failobj)
def update(self, dict):
for k, v in dict.items():
self[k] = v def copy(self): return dict(self)
@@ -446,6 +449,9 @@ def setitem(self, key, item): putenv(key, item) self.data[key] = item
def update(self, dict):
for k, v in dict.items():
self[k] = v try: unsetenv except NameError: