def save(self, key, obj): try: shelve_file = shelve.open('ShelvePersistence') shelve_file[key] = obj finally: shelve_file.close()