This func is used to saving data to txt file support data type: list: Fully support dict: Only save dict key str: will save single char to each line tuple: Fully support set: Fully support :param data: data :param path: path to save :type path: str :param
(data, path, end='\n')
| 62 | |
| 63 | |
| 64 | def save_txt_file(data, path, end='\n'): |
| 65 | """ |
| 66 | This func is used to saving data to txt file |
| 67 | support data type: |
| 68 | list: Fully support |
| 69 | dict: Only save dict key |
| 70 | str: will save single char to each line |
| 71 | tuple: Fully support |
| 72 | set: Fully support |
| 73 | :param data: data |
| 74 | :param path: path to save |
| 75 | :type path: str |
| 76 | :param end: |
| 77 | :type end: str |
| 78 | :return: None |
| 79 | """ |
| 80 | if type(data) not in [list, dict, str, tuple, set] or type(path) != str: |
| 81 | raise TypeError |
| 82 | |
| 83 | remove_old_file(path) |
| 84 | |
| 85 | with open(path, 'a', encoding='utf-8') as f: |
| 86 | for item in data: |
| 87 | f.write(str(item) + end) |
| 88 | |
| 89 | |
| 90 | def save_variable(variable, path): |
no test coverage detected