import json
#读取json文件,提取诗词内容逐行放入txt文档
with open("poem.json", 'r', encoding='utf-8') as f:
temp = json.loads(f.read())
for item in temp:
if len(item['paragraphs'])!=0:
str = ''
for i in item['paragraphs']:
str = str + i
with open("poem.txt", 'a', encoding='utf-8') as f:
f.write(str+"\n")
print(index)
python遍历JSON文件,将某字段按行存入txt文件
最新推荐文章于 2024-10-04 15:08:50 发布