From 65e5399081e23d7b1efbf685096c65d0a0ab912b Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 26 Mar 1998 22:12:22 +0000 Subject: Don't write "if self.dict: self.dict.close()"; just write "self.dict.close()" and ignore the exception. The "if self.dict:" part would be calculated through len(self.dict.keys()), which is very expensive for a large dictionary... --- Lib/shelve.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Lib/shelve.py') diff --git a/Lib/shelve.py b/Lib/shelve.py index 9b65a0911f..6bdc0305dd 100644 --- a/Lib/shelve.py +++ b/Lib/shelve.py @@ -75,8 +75,7 @@ class Shelf: def close(self): try: - if self.dict: - self.dict.close() + self.dict.close() except: pass self.dict = 0 -- cgit v1.2.1