Skip to content

Commit

Permalink
create safe read pickle function
Browse files Browse the repository at this point in the history
  • Loading branch information
jdebacker committed Apr 24, 2018
1 parent d19e5ed commit 0c345b0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ogusa/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,15 @@ def dict_compare(fname1, pkl1, fname2, pkl2, tol, verbose=False,
return False

return check


def safe_read_pickle(file_path):
'''
This function reads a pickle from Python 2 into Python 2 or Python 3
'''
with open(file_path, 'rb') as f:
try:
obj = pickle.load(f, encoding='latin1')
except TypeError:
obj = pickle.load(f)
return obj

0 comments on commit 0c345b0

Please sign in to comment.