import shelve
from contextlib import closing
with closing(shelve.open('test_shelf.db')) as s:
existing = s['key1']
print(existing)
import shelve
from contextlib import closing
with closing(shelve.open('test_shelf.db')) as s:
s['key1'] = {'int':10, 'float':9.5, 'string': 'Sample data'}
writeback 写会参数可以减少犯错,但是会降低性能