python 字典转json

def submit(path):
    data = []
    for line in open(path):
        if not line.strip():
            continue
        _ = json.loads(line.strip())
        res = predict(_["text"])
        data.append(json.dumps({"id":_['id'],"text":_["text"],"label": res}, ensure_ascii=False))
    open("ner_predict.json", "w").write("\n".join(data))

 

posted @ 2020-10-30 14:31  cup_leo  阅读(296)  评论(0编辑  收藏  举报