修正数据到json格式

时间:2020-10-27 16:12:03   收藏:0   阅读:34
def test():
    file_path = r./data/0914/position_predict_100.txt
    save_path = r./data/0914/position_predict_100.json
    save_dict = {}
    with open(file_path, r, encoding=utf8) as fr:
        with open(save_path, w, encoding=utf8) as fw:
            content = fr.readlines()
            for each in content:
                each_dict = dict(eval(each.strip()))
                save_dict[each_dict["_id"]] = each_dict
            json.dump(save_dict, fw, indent=4)
            print(ok)

 

原文:https://www.cnblogs.com/demo-deng/p/13884341.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!