FileOps API
Purpose
This module provides a unified interface for file operations in RDEToolKit. It enables reading and writing of various file formats such as JSON, YAML, TOML, and CSV through a concise and consistent API.
Key Features
File Reading
- Reading JSON, YAML, TOML, and CSV files
- Automatic encoding detection and processing
- Error handling and exception processing
File Writing
- File output in various formats
- Saving in appropriate formats
- Character encoding management
src.rdetoolkit.fileops.readf_json(path)
A function that reads a JSON file and returns the JSON object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str | Path
|
The path to the JSON file. |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
dict[str, Any]: The parsed json object. |
Raises:
Type | Description |
---|---|
StructuredError
|
If an error occurs while processing the file. |
src.rdetoolkit.fileops.writef_json(path, obj, *, enc='utf_8')
Writes an content to a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str | Path
|
Path to the destination JSON file. |
required |
obj |
dict[str, Any]
|
Invoice object to be serialized and written. |
required |
enc |
str
|
Encoding to use when writing the file. Defaults to "utf_8". |
'utf_8'
|
Returns:
Type | Description |
---|---|
dict[str, Any]
|
dict[str, Any]: The parsed json object. |
Practical Usage
JSON File Operations
json_operations.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
File Operations with Error Handling
safe_file_operations.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|