Skip to content

Instantly share code, notes, and snippets.

@gbin
Created May 27, 2015 17:54
Show Gist options
  • Save gbin/b5353174085e6615cdb3 to your computer and use it in GitHub Desktop.
Save gbin/b5353174085e6615cdb3 to your computer and use it in GitHub Desktop.
Converting a Python 2 berkeley db shelve to a python 3 one.
## py3
import shelve
import dbm
import pickle
with dbm.open('source', 'r') as source: # no .db here on purpose.
with shelve.open('destination.db') as destination:
for key in source.keys():
key = key.decode('utf-8')
value = pickle.loads(source[key])
print(key, value)
destination[key] = value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment