MCPcopy Create free account
hub / github.com/davisking/dlib / save_pickled_compatible

Function save_pickled_compatible

tools/python/test/utils.py:4–17  ·  view source on GitHub ↗

Save an object to the specified file in a backward compatible way for Pybind objects. See: http://pybind11.readthedocs.io/en/stable/advanced/classes.html#pickling-support and https://github.com/pybind/pybind11/issues/271

(obj_to_pickle, file_name)

Source from the content-addressed store, hash-verified

2import sys
3
4def save_pickled_compatible(obj_to_pickle, file_name):
5 '''
6 Save an object to the specified file in a backward compatible
7 way for Pybind objects. See:
8 http://pybind11.readthedocs.io/en/stable/advanced/classes.html#pickling-support
9 and https://github.com/pybind/pybind11/issues/271
10 '''
11 try:
12 import cPickle as pickle # Use cPickle on Python 2.7
13 except ImportError:
14 import pickle
15 data = pickle.dumps(obj_to_pickle, 2)
16 with open(file_name, "wb") as handle:
17 handle.write(data)
18
19def load_pickled_compatible(file_name):
20 '''

Callers

nothing calls this directly

Calls 1

writeMethod · 0.45

Tested by

no test coverage detected