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

Function read_jsonl

tools/utils.py:97–116  ·  view source on GitHub ↗

读取jsonl文件,并返回包含每行JSON对象的列表。 :param file_path: .jsonl文件的路径 :return: 包含每行JSON对象的列表

(file_path)

Source from the content-addressed store, hash-verified

95
96
97def read_jsonl(file_path):
98 """
99 读取jsonl文件,并返回包含每行JSON对象的列表。
100
101 :param file_path: .jsonl文件的路径
102 :return: 包含每行JSON对象的列表
103 """
104 data = []
105
106 try:
107 with open(file_path, 'r', encoding='utf-8') as f:
108 for line in f:
109 # 去除空行
110 if line.strip():
111 json_obj = json.loads(line.strip()) # 解析每一行的JSON对象
112 data.append(json_obj)
113 return data
114 except Exception as e:
115 print(f"Error reading {file_path}: {e}")
116 return None
117
118def write_jsonl(data, path, mode="a",encoding='utf-8'):
119 with open(path, mode, encoding=encoding) as f:

Callers 2

extract_descFunction · 0.90
process_single_fileFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected