pickle.dump(obj, file, protocol=None, *, fix_imports=True)
pickle.load(file, *, fix_imports=True, encoding="ASCII", errors="strict")
|obj||pickled representation of obj to the open file object file|
|protocol||an integer, tells the pickler to use the given protocol,|
|file||The file argument must have a write() method |
Function utility for save and load
Save data to and from file
Objects like numbers, lists, dictionaries,nested structures and class instance objects live in your computer’s memory and are lost as soon as the script ends.
pickle stores data persistently in separate file.
pickled representation of an object is always a bytes object in all cases so one must open files in
wb to store data and
rb to load data from pickle.
the data may may be off any kind , for example,
The following types can be pickled
- None, True, and False
- integers, floating point numbers, complex numbers
- strings, bytes, bytearrays
- tuples, lists, sets, and dictionaries containing only picklable objects
- functions defined at the top level of a module (using def, not lambda)
- built-in functions defined at the top level of a module
- classes that are defined at the top level of a module
- instances of such classes whose dict or the result of calling getstate()