caikit.core.toolkit.fileio
Basic routines for reading and writing common file types.
Functions
|
Load a string from a file with utf8 encoding. |
|
Load a list of files from a text file with utf8 encoding |
|
Write a string to a text file with utf8 encoding. |
|
Load a binary string from a file. |
|
Write a binary buffer to a file. |
|
Load a csv into a list-of-lists. |
|
Write a list-of-lists to a csv file. |
|
Load a csv into a list-of-dicts. |
|
Write a list of dicts to a csv file. |
|
Load a json file into a dictionary. |
|
Save a dictionary into a json file. |
|
Load a yaml file into a dictionary. |
|
Save a dictionary into a yaml file. |
|
Load an object from a pickle file. |
|
Save an object to a pickle file. |
|
Write the given raw string content to output file. |
|
Compress a given folder recursively to an archive with a given extension format |
Module Contents
- caikit.core.toolkit.fileio.load_txt(filename)[source]
Load a string from a file with utf8 encoding.
- caikit.core.toolkit.fileio.load_txt_lines(filename)[source]
Load a list of files from a text file with utf8 encoding
- caikit.core.toolkit.fileio.save_txt(text, filename, mode='w')[source]
Write a string to a text file with utf8 encoding.
- caikit.core.toolkit.fileio.save_csv(text_list, filename, mode='w')[source]
Write a list-of-lists to a csv file.
- caikit.core.toolkit.fileio.save_dict_csv(dict_list, filename, mode='w')[source]
Write a list of dicts to a csv file.
- caikit.core.toolkit.fileio.save_json(save_dict, filename, mode='w')[source]
Save a dictionary into a json file.
- caikit.core.toolkit.fileio.save_yaml(save_dict, filename, mode='w')[source]
Save a dictionary into a yaml file.
- caikit.core.toolkit.fileio.save_pickle(obj, filename, mode='wb')[source]
Save an object to a pickle file.
- caikit.core.toolkit.fileio.save_raw(save_content, filename, mode='w')[source]
Write the given raw string content to output file.
- caikit.core.toolkit.fileio.compress(dir_path, output_path=None, extension='zip')[source]
Compress a given folder recursively to an archive with a given extension format
- Args:
dir_path (str): Path of directory to compress output_path: (Optional) str
Output path where the archive is created. Defaults to current path + ‘archive’ + format extension >>> compress(‘.’, ‘my/path’, ‘tar’) >>> # saves to ‘my/path/archive.tar’
- extension: (Optional) (one of: zip/tar/gztar/bztar/xztar depending on module availability)
Defaults to .zip
- Returns:
str: Path to created archive