写入YAML文件。 参数: - file_path (str): 文件路径。 - data (dict): 要写入的YAML数据。 - mode (str): 写入模式,默认为 'a'(追加模式),可以选择 'w'(覆盖模式)。 - encoding (str): 写入文件的编码格式,默认为 'utf-8'。
(file_path, data, mode, encoding='utf-8')
| 565 | |
| 566 | |
| 567 | def write_yaml(file_path, data, mode, encoding='utf-8'): |
| 568 | """ |
| 569 | 写入YAML文件。 |
| 570 | |
| 571 | 参数: |
| 572 | - file_path (str): 文件路径。 |
| 573 | - data (dict): 要写入的YAML数据。 |
| 574 | - mode (str): 写入模式,默认为 'a'(追加模式),可以选择 'w'(覆盖模式)。 |
| 575 | - encoding (str): 写入文件的编码格式,默认为 'utf-8'。 |
| 576 | """ |
| 577 | logger.info(f"写入YAML文件: {file_path}") |
| 578 | with open(file_path, mode, encoding=encoding) as f: |
| 579 | yaml.dump(data, f, allow_unicode=True) |
| 580 | |
| 581 | |
| 582 | def write_csv(file_path, data, mode, chunk_size, encoding='utf-8'): |