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)
原文地址:https://www.cnblogs.com/qlling/p/13754270.html