load_pickle¶
- pyhelpers.store.load_pickle(path_to_file, verbose=False, prt_kwargs=None, raise_error=False, **kwargs)[source]¶
Loads data from a Pickle file.
The function is intended for use with trusted data sources only.
- Parameters:
path_to_file (str | os.PathLike) – Path where the pickle file is saved.
verbose (bool | int) – Whether to print relevant information to the console; defaults to
False
.prt_kwargs (dict | None) – [Optional] Additional parameters for
pyhelpers.store._check_loading_path()
; defaults toNone
.raise_error (bool) – Whether to raise the provided exception; if
raise_error=False
(default), the error will be suppressed.kwargs – [Optional] Additional parameters for the function pickle.load().
- Returns:
Data retrieved from the specified path
path_to_file
.- Return type:
Any
Note
Ensure that
path_to_file
comes from a trusted source to avoid deserialisation vulnerabilities.Example data can be referred to the function
save_pickle()
.
Examples:
>>> from pyhelpers.store import load_pickle >>> from pyhelpers.dirs import cd >>> pickle_pathname = cd("tests", "data", "dat.pickle") >>> pickle_dat = load_pickle(pickle_pathname, verbose=True) Loading ".\tests\data\dat.pickle" ... Done. >>> pickle_dat Longitude Latitude City London -0.127647 51.507322 Birmingham -1.902691 52.479699 Manchester -2.245115 53.479489 Leeds -1.543794 53.797418