Python Yaml 写入中文乱码的问题(allow_unicode=True)

def set_testdata(testdata, ymlname="capst.yml"):
    curpath = os.path.dirname(os.path.realpath(__file__))
    yamlpath = os.path.join(curpath, ymlname)

    # 写入到yaml文件
    # with open(yamlpath, "w", encoding="utf-8") as f:
    #     yaml.dump(testdata, f, Dumper=yaml.RoundTripDumper)

    with open(yamlpath, "w", encoding="utf-8") as f:
        yaml.dump(testdata, f, allow_unicode=True)

 

posted on 2020-09-30 14:09  studyAppStore  阅读(1246)  评论(0编辑  收藏  举报