Created
July 2, 2015 09:52
-
-
Save pklaus/a635d4cfc305ba0e4cb6 to your computer and use it in GitHub Desktop.
A command line tool to convert between pickle protocol versions
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
#!/usr/bin/env python | |
import pickle | |
import argparse | |
import sys | |
def main(): | |
parser = argparse.ArgumentParser(description='Convert between pickle protocol versions.') | |
parser.add_argument('input_file') | |
parser.add_argument('output_file') | |
parser.add_argument('--version', default=2, type=int, help='The pickle protocol version to write the OUTPUT_FILE.') | |
args = parser.parse_args() | |
with open(args.input_file, 'rb') as f: | |
try: | |
data = pickle.load(f) | |
except ValueError as e: | |
sys.stderr.write(str(e) + "\nPlease use a more recent version of Python to do the conversion.\n") | |
sys.exit(1) | |
with open(args.output_file, 'wb') as f: | |
pickle.dump(data, f, args.version) | |
print("Done!") | |
if __name__ == "__main__": main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment