python jsonl文件读取(jsonlines)
python jsonl文件读取(jsonlines)写入import jsonlinesdef parse(self, response):jsonresponse=json.loads(response.text)with jsonlines.open('output.jsonl',mode='a') as writer:writer.write(j...
文章共236字 · 阅读需要大约1分钟
一键AI生成摘要,助你高效阅读
问答
·
python jsonl文件读取(jsonlines)
写入
import jsonlines
def parse(self, response):
jsonresponse=json.loads(response.text)
with jsonlines.open('output.jsonl',mode='a') as writer:
writer.write(jsonresponse)
读取
import jsonlines
with open("xxxx.jl", "r+", encoding="utf8") as f:
for item in jsonlines.Reader(f):
print(item)
json lines文件是一种便于存储结构化数据的格式,可以一次处理一条记录。可以用作日志文件或者其他。每条json数据之间存在一个"\n"分隔符。
具体信息可以查看jsonlines官网
import json_lines
with open('fileName.jsonl', 'rb') as f:
for item in json_lines.reader(f):
print(item)
更多推荐
已为社区贡献1条内容
所有评论(0)