file_handler
FileHandler
Source code in libs\cafex_core\src\cafex_core\handlers\file_handler.py
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
add_data_to_json_file(filepath, data)
staticmethod
Adds data to an existing JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str
|
The path of the JSON file. |
required |
data
|
dict
|
The data to be added to the JSON file. |
required |
Source code in libs\cafex_core\src\cafex_core\handlers\file_handler.py
36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
create_json_file(directory, filename, data=None, indent=2)
staticmethod
Creates a new JSON file at the specified directory with the given filename.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory
|
str
|
The directory where the file will be created. |
required |
filename
|
str
|
The name of the file to be created. |
required |
data
|
list or dict
|
The data to be written to the file. Can be a list or a dictionary. |
None
|
indent
|
int
|
The number of spaces to use for indentation. Default is 2. |
2
|
Source code in libs\cafex_core\src\cafex_core\handlers\file_handler.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
delete_file(filepath)
staticmethod
Deletes the file at the specified filepath.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str
|
The path of the file to be deleted. |
required |
Source code in libs\cafex_core\src\cafex_core\handlers\file_handler.py
24 25 26 27 28 29 30 31 32 33 34 |
|
read_data_from_json_file(filepath)
staticmethod
Reads data from a JSON file and returns it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str
|
The path of the JSON file. |
required |
Returns:
Type | Description |
---|---|
dict or list: The data read from the JSON file. |
Source code in libs\cafex_core\src\cafex_core\handlers\file_handler.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|