summaryrefslogtreecommitdiff
path: root/Lib/UserDict.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2000-08-08 16:12:54 +0000
committerGuido van Rossum <guido@python.org>2000-08-08 16:12:54 +0000
commit164452cec416fbe032c1173d58ad89adab38820b (patch)
treedc5b8769a82ffc778d27a8e0679bda4c5125100e /Lib/UserDict.py
parent2b042ded19bc7efa43551da297c29dc142b7d73c (diff)
downloadcpython-git-164452cec416fbe032c1173d58ad89adab38820b.tar.gz
Barry's patch to implement the new setdefault() method.
Diffstat (limited to 'Lib/UserDict.py')
-rw-r--r--Lib/UserDict.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/UserDict.py b/Lib/UserDict.py
index 3c48415771..9b6e73b50f 100644
--- a/Lib/UserDict.py
+++ b/Lib/UserDict.py
@@ -34,3 +34,7 @@ class UserDict:
self.data[k] = v
def get(self, key, failobj=None):
return self.data.get(key, failobj)
+ def setdefault(self, key, failobj=None):
+ if not self.data.has_key(key):
+ self.data[key] = failobj
+ return self.data[key]