多条dict写入json文件的时候,怎么加换行符
importjsondata=[]withopen('target.json')asfile:forlineinfile:data.append(json.loads(l...
import json
data = []
with open('target.json') as file:
for line in file:
data.append(json.loads(line))
with open('testoutput.json', 'w') as file:
for line in data:
json.dump(line, file)
最后一行写入的数据打开是一行。。我想每次写入一个line的时候,加个换行符。怎么加? 展开
data = []
with open('target.json') as file:
for line in file:
data.append(json.loads(line))
with open('testoutput.json', 'w') as file:
for line in data:
json.dump(line, file)
最后一行写入的数据打开是一行。。我想每次写入一个line的时候,加个换行符。怎么加? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询