Load the Python object from the given path. Parameters ---------- object_path : str The path where the object is saved. Returns ------- Any The object existing at the provided location.
(object_path: str)
| 73 | |
| 74 | |
| 75 | def unpickle_python_object(object_path: str) -> Any: |
| 76 | """ |
| 77 | Load the Python object from the given path. |
| 78 | |
| 79 | Parameters |
| 80 | ---------- |
| 81 | object_path : str |
| 82 | The path where the object is saved. |
| 83 | |
| 84 | Returns |
| 85 | ------- |
| 86 | Any |
| 87 | The object existing at the provided location. |
| 88 | |
| 89 | """ |
| 90 | if not os.path.isfile(object_path): |
| 91 | raise FileNotFoundError("File {} does not exist locally!".format(object_path)) |
| 92 | try: |
| 93 | with open(object_path, "rb") as save_file: |
| 94 | obj = pickle.load(save_file) |
| 95 | except Exception: |
| 96 | raise pickle.UnpicklingError( |
| 97 | "Failed to load object from {}!".format(object_path) |
| 98 | ) |
| 99 | return obj |
no outgoing calls
no test coverage detected