summaryrefslogtreecommitdiffstats
path: root/Lib/shelve.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2002-10-18 08:58:14 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2002-10-18 08:58:14 (GMT)
commite4913c9987d88f5a1bd52753afe8eb6bee32f6e9 (patch)
treec1c13c2180af24c3c5a6b2044b749b31e12956f8 /Lib/shelve.py
parentd7bc0fec38e1b2de43e09a417907c12dab38e750 (diff)
downloadcpython-e4913c9987d88f5a1bd52753afe8eb6bee32f6e9.zip
cpython-e4913c9987d88f5a1bd52753afe8eb6bee32f6e9.tar.gz
cpython-e4913c9987d88f5a1bd52753afe8eb6bee32f6e9.tar.bz2
Patch #624936: Implement __contains__.
Diffstat (limited to 'Lib/shelve.py')
-rw-r--r--Lib/shelve.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/shelve.py b/Lib/shelve.py
index fa2a136..ae8df3f 100644
--- a/Lib/shelve.py
+++ b/Lib/shelve.py
@@ -19,7 +19,7 @@ object):
# such key)
del d[key] # delete data stored at key (raises KeyError
# if no such key)
- flag = d.has_key(key) # true if the key exists
+ flag = d.has_key(key) # true if the key exists; same as "key in d"
list = d.keys() # a list of all existing keys (slow!)
d.close() # close it
@@ -61,6 +61,9 @@ class Shelf:
def has_key(self, key):
return self.dict.has_key(key)
+ def __contains__(self, key):
+ return self.dict.has_key(key)
+
def get(self, key, default=None):
if self.dict.has_key(key):
return self[key]