-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert_pickles.py
executable file
·48 lines (36 loc) · 1.13 KB
/
convert_pickles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 1 11:25:15 2020
@author: cornell
"""
# For converting Python 2 pickles to Python 3
import os
import dill
import pickle
import argparse
def convert(old_pkl):
"""
Convert a Python 2 pickle to Python 3
"""
import pdb; pdb.set_trace()
# Make a name for the new pickle
new_pkl = os.path.splitext(os.path.basename(old_pkl))[0]+"_p3.pkl"
# Convert Python 2 "ObjectType" to Python 3 object
dill._dill._reverse_typemap["ObjectType"] = object
# Open the pickle using latin1 encoding
with open(old_pkl, "rb") as f:
loaded = pickle.load(f, encoding="latin1")
# Re-save as Python 3 pickle
with open(new_pkl, "wb") as outfile:
pickle.dump(loaded, outfile)
if __name__ == "__main__":
'''
parser = argparse.ArgumentParser(
description="Convert a Python 2 pickle to Python 3"
)
parser.add_argument("infile", help="Python 2 pickle filename")
args = parser.parse_args()
convert(args.infile)
'''
convert('/home/cornell/Documents/Projects/AutomatedWarehouse/drake_example/lab.pickle')