MCPcopy Create free account
hub / github.com/KnowledgeXLab/LeanRAG / read_jsonl_chunk

Function read_jsonl_chunk

tools/io_file.py:351–365  ·  view source on GitHub ↗

读取JSONL文件的某一块。 参数: - file_path (str): 文件路径。 - start_line (int): 起始行。 - end_line (int): 结束行。 - encoding (str): 文件编码格式,默认为 'utf-8'。 返回: - list: 该块读取的内容。

(file_path, start_line, end_line, encoding='utf-8')

Source from the content-addressed store, hash-verified

349
350
351def read_jsonl_chunk(file_path, start_line, end_line, encoding='utf-8'):
352 """
353 读取JSONL文件的某一块。
354
355 参数:
356 - file_path (str): 文件路径。
357 - start_line (int): 起始行。
358 - end_line (int): 结束行。
359 - encoding (str): 文件编码格式,默认为 'utf-8'
360
361 返回:
362 - list: 该块读取的内容。
363 """
364 with open(file_path, 'r', encoding=encoding) as f:
365 return [json.loads(line) for _, line in zip(range(start_line), f)][start_line:end_line]
366
367
368# 写入文件函数

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected