Update __init__.py

This commit is contained in:
Max Zwiessele 2015-10-11 01:57:37 +01:00
parent 0b4297bda5
commit 0d74681ee2

View file

@ -43,19 +43,28 @@ def load(file_or_path):
:param file_name: path/to/file.pickle :param file_name: path/to/file.pickle
""" """
try: try:
str = basestring unicode = unicode
except: except NameError:
pass # 'unicode' is undefined, must be Python 3
try: str = str
import cPickle as pickle unicode = str
if isinstance(file_or_path, str): bytes = bytes
with open(file_or_path, 'rb') as f: basestring = (str,bytes)
m = pickle.load(f) else:
# 'unicode' exists, must be Python 2
str = str
unicode = unicode
bytes = str
basestring = basestring try:
import cPickle as pickle
if isinstance(file_or_path, basestring):
with open(file_or_path, 'rb') as f:
m = pickle.load(f)
else: else:
m = pickle.load(file_or_path) m = pickle.load(file_or_path)
except: except:
import pickle import pickle
if isinstance(file_or_path, str): if isinstance(file_or_path, basestring):
with open(file_or_path, 'rb') as f: with open(file_or_path, 'rb') as f:
m = pickle.load(f) m = pickle.load(f)
else: else: