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.
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
path
|
str | Path
|
The path to the JSON file. |
必須 |
戻り値:
| タイプ | デスクリプション |
|---|---|
dict[str, Any]
|
dict[str, Any]: The parsed json object. |
発生:
| タイプ | デスクリプション |
|---|---|
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.
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
path
|
str | Path
|
Path to the destination JSON file. |
必須 |
obj
|
dict[str, Any]
|
Invoice object to be serialized and written. |
必須 |
enc
|
str
|
Encoding to use when writing the file. Defaults to "utf_8". |
'utf_8'
|
戻り値:
| タイプ | デスクリプション |
|---|---|
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 | |