Loading
Loading an VIPicklable object
VIPicklable
objects have a
load method
for loading an object instance :
>>> class MyClass(VIPicklable):
... PICKLE_BLACKLIST = ["unpicklable_attribute"]
...
... def __init__(self):
... self.unpicklable_attribute = "do_not_pickle"
...
>>> obj = MyClass()
>>> obj.save("folder")
>>> obj = MyClass.load("folder")
VIPicklable.load
Load a VIPicklable instance.
Load a VIPicklable instance and all loadable attributes from a file or folder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Union[str, Path]
|
Path to the pickle file |
required |
pickle_dump_kwargs |
dict
|
additionnal arguments to be pass to load_instance method. Default to None. |
None
|
Raises:
Type | Description |
---|---|
FileNotFoundError
|
Pickle file not found |
Returns:
Name | Type | Description |
---|---|---|
VIPicklable |
VIPicklable
|
The instance object |
Source code in /opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/vipickle/mixin.py
Load hooks
Under the hood, the load method does the following :
stateDiagram-v2
[*] --> self.before_load()
self.before_load() --> self.load_instance()
self.load_instance() --> self.load_pickle_blacklisted()
self.load_pickle_blacklisted() --> self.after_load()
self.after_load() --> [*]
One can redefine any of these methods to personnalise the saving process :