Saving
Saving a VIPicklable object
VIPicklable
objects have a
save method
for saving an object instance :
>>> class MyClass(VIPicklable):
... PICKLE_BLACKLIST = ["unpicklable_attribute"]
...
... def __init__(self):
... self.unpicklable_attribute = "do_not_pickle"
...
>>> obj = MyClass()
>>> obj.save("folder")
VIPicklable.save
Save the object instance in a dedicated directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Union[str, Path]
|
Path to the directory |
required |
pickle_dump_kwargs |
dict
|
kwargs to be passed to pickle.dump method. Defaults to None. |
None
|
json_dump_kwargs |
dict
|
kwargs to be passed to json.dump method. Defaults to None. |
None
|
overwrite |
bool
|
If True, overwrite the folder if it exists. |
True
|
Source code in /opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/vipickle/mixin.py
Save hooks
Under the hood, the save method does the following :
stateDiagram-v2
[*] --> self.before_save()
self.before_save() --> self.save_instance()
self.save_instance() --> self.save_config()
self.save_config() --> self.save_pickle_blacklisted()
self.save_pickle_blacklisted() --> self.after_save()
self.after_save() --> [*]
One can redefine any of these methods to personnalise the saving process :