Skip to content

Commit f2d2506

Browse files
committed
add comment about pickling with imported mode
1 parent 49dd565 commit f2d2506

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

py5_docs/Reference/api_en/Sketch_load_pickle.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Load a pickled Python object from a file. The path can be in the data directory,
1717

1818
There are security risks associated with Python pickle files. A pickle file can contain malicious code, so never load a pickle file from an untrusted source.
1919

20+
When using py5 in [imported mode](content-py5-modes-imported-mode), pickling will not work on objects instantiated from new classes you have defined yourself on the main sketch file. This applies to py5's [](sketch_save_pickle) and `load_pickle()` methods, as well as the Python's standard library pickle module methods they depend upon. If you need to pickle objects from classes you defined, move the class definitions to a different .py file that you import as a module or import the classes from. Otherwise, you could also try using [module mode](content-py5-modes-module-mode) if you want to use pickle with your classes and keep all the sketch code in a single file.
21+
2022
@@ example
2123
def setup():
2224
global mouse_x_positions, mouse_y_positions

py5_docs/Reference/api_en/Sketch_save_pickle.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ obj: Any - any non-py5 Python object
1616
@@ description
1717
Pickle a Python object to a file. If `filename` is not an absolute path, it will be saved relative to the current working directory ([](sketch_sketch_path)). The saved file can be reloaded with [](sketch_load_pickle).
1818

19-
Object "pickling" is a method for serializing objects and saving them to a file for later retrieval. The recreated objects will be clones of the original objects. Not all Python objects can be saved to a Python pickle file. This limitation prevents any py5 object from being pickled.
19+
Object "pickling" is a technique for serializing objects and saving them to a file for later retrieval. The recreated objects will be clones of the original objects. Not all Python objects can be saved to a Python pickle file. This limitation prevents any py5 object from being pickled.
20+
21+
When using py5 in [imported mode](content-py5-modes-imported-mode), pickling will not work on objects instantiated from new classes you have defined yourself on the main sketch file. This applies to py5's `save_pickle()` and [](sketch_load_pickle) methods, as well as the Python's standard library pickle module methods they depend upon. If you need to pickle objects from classes you defined, move the class definitions to a different .py file that you import as a module or import the classes from. Otherwise, you could also try using [module mode](content-py5-modes-module-mode) if you want to use pickle with your classes and keep all the sketch code in a single file.
2022

2123
@@ example
2224
data = dict(mouse_x=[], mouse_y=[])

0 commit comments

Comments
 (0)