From e4913c9987d88f5a1bd52753afe8eb6bee32f6e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Fri, 18 Oct 2002 08:58:14 +0000 Subject: [PATCH] Patch #624936: Implement __contains__. --- Lib/shelve.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/shelve.py b/Lib/shelve.py index fa2a136dcb4..ae8df3fc1ae 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]