Created
May 27, 2015 17:54
-
-
Save gbin/b5353174085e6615cdb3 to your computer and use it in GitHub Desktop.
Converting a Python 2 berkeley db shelve to a python 3 one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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