Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> import shelve
- >>> from contextlib import contextmanager
- >>> class Database:
- ... def __init__(self, path):
- ... self.path = path
- ...
- ... @contextmanager
- ... def open(self):
- ... s = shelve.open(self.path, writeback=True)
- ... try:
- ... yield s
- ... finally:
- ... s.close()
- ...
- >>>
- >>> d = Database('/home/zach/.tweet_poster/cache')
- >>>
- >>> with d.open() as db:
- ... print(db['108710608601493504'])
- ...
- Traceback (most recent call last):
- File "/usr/lib/python3.2/shelve.py", line 111, in __getitem__
- value = self.cache[key]
- KeyError: '108710608601493504'
- During handling of the above exception, another exception occurred:
- Traceback (most recent call last):
- File "<stdin>", line 2, in <module>
- File "/usr/lib/python3.2/shelve.py", line 113, in __getitem__
- f = BytesIO(self.dict[key.encode(self.keyencoding)])
- KeyError: b'108710608601493504'
- >>>
Add Comment
Please, Sign In to add comment