[Python-checkins] r58221 - in python/trunk: Doc/library/os.rst Lib/os.py
georg.brandl
python-checkins at python.org
Thu Sep 20 19:57:59 CEST 2007
Author: georg.brandl
Date: Thu Sep 20 19:57:59 2007
New Revision: 58221
Modified:
python/trunk/Doc/library/os.rst
python/trunk/Lib/os.py
Log:
Patch #1181: add os.environ.clear() method.
Modified: python/trunk/Doc/library/os.rst
==============================================================================
--- python/trunk/Doc/library/os.rst (original)
+++ python/trunk/Doc/library/os.rst Thu Sep 20 19:57:59 2007
@@ -115,9 +115,13 @@
passed to the appropriate process-creation functions to cause child processes
to use a modified environment.
- If the platform supports the :func:`unsetenv` function, you can delete items in
+ If the platform supports the :func:`unsetenv` function, you can delete items in
this mapping to unset environment variables. :func:`unsetenv` will be called
- automatically when an item is deleted from ``os.environ``.
+ automatically when an item is deleted from ``os.environ``, and when
+ :meth:`os.environ.clear` is called.
+
+ .. versionchanged:: 2.6
+ Also unset environment variables when calling :meth:`os.environ.clear`.
.. function:: chdir(path)
Modified: python/trunk/Lib/os.py
==============================================================================
--- python/trunk/Lib/os.py (original)
+++ python/trunk/Lib/os.py Thu Sep 20 19:57:59 2007
@@ -446,6 +446,10 @@
def __delitem__(self, key):
unsetenv(key)
del self.data[key.upper()]
+ def clear(self):
+ for key in self.data.keys():
+ unsetenv(key)
+ del self.data[key]
def has_key(self, key):
return key.upper() in self.data
def __contains__(self, key):
@@ -503,6 +507,10 @@
def __delitem__(self, key):
unsetenv(key)
del self.data[key]
+ def clear(self):
+ for key in self.data.keys():
+ unsetenv(key)
+ del self.data[key]
def copy(self):
return dict(self)
More information about the Python-checkins
mailing list