diff options
author | Barry Warsaw <barry@python.org> | 1997-10-06 17:50:04 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 1997-10-06 17:50:04 (GMT) |
commit | fc3e61cd2816274e49dfd42ddc29b38d3118bd21 (patch) | |
tree | c390fd7fdaadf784df4a5e2f2455d2e63d236818 /Lib | |
parent | c38c5da5d0ce35442e859d64e6cfa734688a470e (diff) | |
download | cpython-fc3e61cd2816274e49dfd42ddc29b38d3118bd21.zip cpython-fc3e61cd2816274e49dfd42ddc29b38d3118bd21.tar.gz cpython-fc3e61cd2816274e49dfd42ddc29b38d3118bd21.tar.bz2 |
UserDict.get(): New method to mirror built-in dictionaries' get()
method.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/UserDict.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Lib/UserDict.py b/Lib/UserDict.py index 2f4f541..3b9b157 100644 --- a/Lib/UserDict.py +++ b/Lib/UserDict.py @@ -26,3 +26,8 @@ class UserDict: else: for k, v in other.items(): self.data[k] = v + def get(self, key, failobj=None): + if self.data.has_key(key): + return self.data[key] + else: + return failobj |