Save the given Python object to the given path. Parameters ---------- obj : Any Any *picklable* Python object. object_path : str The path where the object will be saved. Returns -------
(obj: Any, object_path: str)
| 45 | |
| 46 | |
| 47 | def pickle_python_object(obj: Any, object_path: str): |
| 48 | """ |
| 49 | Save the given Python object to the given path. |
| 50 | |
| 51 | Parameters |
| 52 | ---------- |
| 53 | obj : Any |
| 54 | Any *picklable* Python object. |
| 55 | object_path : str |
| 56 | The path where the object will be saved. |
| 57 | |
| 58 | Returns |
| 59 | ------- |
| 60 | |
| 61 | """ |
| 62 | parent_dir = "/".join(object_path.split("/")[:-1]) |
| 63 | if not os.path.exists(parent_dir): |
| 64 | os.makedirs(parent_dir) |
| 65 | |
| 66 | try: |
| 67 | with open(object_path, "wb") as save_file: |
| 68 | pickle.dump(obj, save_file) |
| 69 | except Exception: |
| 70 | raise pickle.PicklingError( |
| 71 | "Failed to save object {} to {}!".format(str(obj), object_path) |
| 72 | ) |
| 73 | |
| 74 | |
| 75 | def unpickle_python_object(object_path: str) -> Any: |
no outgoing calls
no test coverage detected