10 examples of 'pickle load file' in Python

Every line of 'pickle load file' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
4def load_pickle(file_name):
5 '''Easy interface to Python cPickle persistence module.
6
7 ::
8
9 abjad> t = Note(0, (1, 4))
10 abjad> f(t)
11 c'4
12 abjad> iotools.dump_pickle(t, 'temp.pkl')
13
14 ::
15
16 abjad> new = iotools.load_pickle('temp.pkl')
17 abjad> new
18 Note(c', 4)
19
20 .. versionchanged:: 1.1.2
21 renamed ``persistencetools.pickle_load( )`` to
22 ``iotools.load_pickle( )``.
23
24 .. versionchanged:: 1.1.2
25 renamed ``persistencetools.load_pickle( )`` to
26 ``iotools.load_pickle( )``.
27 '''
28
29 f = open(file_name, 'r')
30 data = cPickle.load(f)
31 f.close( )
32 return data
114def load_dump(pickle_file):
115 with open(pickle_file, 'rb') as f:
116 data = pickle.load(f, encoding='bytes')
117 return data
10def load_pickle(filename):
11 pkl_file = open(filename, 'rb')
12 data = pickle.load(pkl_file)
13 return data
11def unpickle(file):
12 fo = open(file, 'rb')
13 dict = cPickle.load(fo)
14 fo.close()
15 return dict
1792def load(filename):
1793 """
1794 Load a class from a file.
1795
1796 @return: Body saved in file
1797 @rtype: Body
1798 """
1799 ff = open(filename,'r')
1800 myclass = pickle.load(ff)
1801 ff.close()
1802 return myclass
668def load(filename):
669 """ Unpickle class instance. """
670 import pickle
671 return pickle.load(open(filename, 'rb'))
391def pickle_load(path, filename):
392 """
393 Save data to Pickle file (*.pkl). Allows saving dictionary or other
394 data in a way that json cannot always be saved due to json formatting
395 rules.
396
397 :Args:
398 :path: path to file (no trailing slash)
399 :filename: filename including extension
400 :data: Data to be pickled.
401 :encoding: 'Machine' or 'Human' - determines whether file contents
402 can be viewed in a text editor.
403
404 :returns: saved data. (Assumes success; errors will raise exception.)
405
406 """
407 with open("%s/%s" % (path, filename), "rb") as f:
408 return Pickle.load(f)
12def _safe_unpickle(file_name):
13 with open(file_name, "rb") as data_file:
14 if sys.version_info >= (3, 0):
15 # python3 unpickling of python2 unicode
16 data = pickle.load(data_file, encoding="latin1")
17 else:
18 data = pickle.load(data_file)
19 return data
62def load(filename, bzip2=False, gzip=False):
63 """
64 load(filename):
65
66 Loads an object from filename and returns it.
67
68 INPUT:
69 filename -- a string that defines a valid file. If the
70 file doesn't exist then an IOError exception is raised.
71
72 OUTPUT:
73 An almost arbitrary object.
74 """
75 if bzip2:
76 os.system("bunzip2 -f -k %s"%(filename + ".bz2"))
77 if gzip:
78 os.system("cat %s.gz | gunzip -f > %s"%(filename,filename))
79 assert os.path.exists(filename)
80 o = open(filename,"r")
81 X = cPickle.load(o)
82 if bzip2 or gzip:
83 os.remove(filename)
84 return X
16def load_with_pickle(path, name):
17 with open(os.path.join(path, name), 'rb') as f:
18 return pickle.load(f)

Related snippets