New submission from Martin Horcicka:
This patch makes os.environ.clear() to have the same effect as:
for name in os.environ.keys():
del os.environ[name]
I believe that most people expect the effects to be the same anyway.
The practical benefit is a simpler redefinition of the whole environment
if desired (e.g. in scripts run via sudo on unix systems).
----------
components: Library (Lib)
files: os.py.patch
messages: 56048
nosy: horcicka
severity: normal
status: open
title: Redefine clear() for os.environ to use unsetenv() if possible
type: behavior
__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1181>
__________________________________
Index: Lib/os.py
===================================================================
--- Lib/os.py (revision 58212)
+++ Lib/os.py (working copy)
@@ -446,6 +446,11 @@
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 +508,11 @@
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)
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com