os.environ.copy()['COPY_HUH'] = "not really"

Jeff Epler jepler at unpythonic.net
Tue Apr 30 16:20:22 EDT 2002


Under Python2.1 and earlier (back to 1.5.2):
>>> import os
>>> os.environ.copy()['COPY_HUH'] = "not really"
>>> print os.environ['COPY_HUH']
not really

Under even 2.3a0 (CVS):
>>> import os
>>> os.environ.copy()['COPY_HUH'] = "not really"
>>> os.system("echo $COPY_HUH")
not really
0

My expectation is that modifying a copy of os.environ would not actually
modify the environment either in the current session or for children
created with os.system ...

dict(os.environ) seems to be the trick on versions of Python that have
it, os.environ.data on versions that don't.

Jeff





More information about the Python-list mailing list