Python Pages Doc Ic Ac Uk CPP Lessons CPP 10 Files 05 Pickle HTML
Python Pages Doc Ic Ac Uk CPP Lessons CPP 10 Files 05 Pickle HTML
If you need to save Python data structures that are more complex, and only expect to load them in the future
into Python, you can also consider using Python’s pickle module.
The pickle module is used for storing Python object structures into a file (and retrieving it back into memory at a
later time).
For example, you may use it to save your Machine Learning model that you have been spending the whole
week training.
You pickle your Python objects onto the disk as a binary file (serialisation), and you unpickle them from the disk
into memory (deserialisation).
You can pickle integers, floats, booleans, strings, tuples, lists, sets, dictionaries (that contain objects that can be
pickled), classes, and functions. No pickled gherkins, sorry!
Health warnings!
pickle is specific to Python. You probably should not use it if you need to share your data across different
programming languages
Make sure you use the same Python version. Pickle might not work correctly with different versions of
Python
Do not unpickle data from untrusted sources. There might be malicious code inside the file!
Previous Next