写入JSONL文件的某一块。 参数: - file_path (str): 文件路径。 - chunk (list): 要写入的数据块。 - mode (str): 写入模式,默认为 'a'(追加模式),可以选择 'w'(覆盖模式)。 - encoding (str): 写入文件的编码格式,默认为 'utf-8'。
(file_path, chunk, mode, encoding='utf-8')
| 471 | |
| 472 | |
| 473 | def write_jsonl_chunk(file_path, chunk, mode, encoding='utf-8'): |
| 474 | """ |
| 475 | 写入JSONL文件的某一块。 |
| 476 | |
| 477 | 参数: |
| 478 | - file_path (str): 文件路径。 |
| 479 | - chunk (list): 要写入的数据块。 |
| 480 | - mode (str): 写入模式,默认为 'a'(追加模式),可以选择 'w'(覆盖模式)。 |
| 481 | - encoding (str): 写入文件的编码格式,默认为 'utf-8'。 |
| 482 | """ |
| 483 | with open(file_path, mode, encoding=encoding) as f: |
| 484 | for entry in chunk: |
| 485 | json.dump(entry, f, ensure_ascii=False) |
| 486 | f.write('\n') |
| 487 | |
| 488 | |
| 489 | def write_csv(file_path, data, mode, chunk_size, encoding='utf-8'): |