load_file
Loads data from a file path by reading its bytes and delegating to load_str_bytes, with automatic protocol detection based on file extensions like .json or .pkl.
def load_file(
path: str | Path,
content_type: str | None = None,
encoding: str = 'utf8',
proto: Protocol | None = None,
allow_pickle: bool = False,
json_loads: Callable[[str], Any] = json.loads
) - > Any
Loads and parses the content of a file from a given path based on its extension or a specified protocol.
Parameters
| Name | Type | Description |
|---|---|---|
| path | `str | Path` |
| content_type | `str | None` = None |
| encoding | str = 'utf8' | The character encoding used to decode the file bytes into a string. |
| proto | `Protocol | None` = None |
| allow_pickle | bool = False | Whether to allow the loading of pickled data, which can be a security risk. |
| json_loads | Callable[[str], Any] = json.loads | The JSON loading function to use when parsing JSON content. |
Returns
| Type | Description |
|---|---|
Any | The deserialized data from the file, such as a dictionary from JSON or a Python object from a pickle file. |