Created
January 25, 2019 04:20
-
-
Save jerryan999/4e0eaf5b6f53a3c75b4295819de4cda8 to your computer and use it in GitHub Desktop.
convert between pickcle2 and pickcle3
This file contains 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
import pickle | |
import argparse | |
from os import listdir | |
from os.path import isfile, join | |
import sys | |
def convert(input_file_with_path, output_file_with_path): | |
with open(input_file_with_path, 'rb') as f_in: | |
data = pickle.load(f_in) | |
with open(output_file_with_path, 'wb') as f_out: | |
pickle.dump(data, f_out, protocol=2) | |
print("converted {}".format(output_file_with_path)) | |
if __name__ == "__main__": | |
# FixMe | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--input_dir", type=str, required=True, help="input dir") | |
parser.add_argument("--output_dir", type=str, default=None, help="output dir") | |
args, unknown = parser.parse_known_args(sys.argv) | |
all_files = [f for f in listdir(args.input_dir) if isfile(join(args.input_dir, f))] | |
for file in all_files: | |
input_file_with_path = "{}/{}".format(args.input_dir, file) | |
output_file_with_path = "{}/{}".format(args.output_dir, file) | |
convert(input_file_with_path, output_file_with_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment