json 是 python 内置
yaml 需要安装
pip install pyyaml
对于同样一段数据:
test_data = {"金山中学":{"101班":{"王宁": {"语文":33,"数学":22,"英语":18}}}}
yaml
和 json
文件中:with open("yaml.yml", 'w') as f:yaml.dump(test_data, f, allow_unicode=True)
with open("json.json", "w") as f:json.dump(test_data, f, ensure_ascii=False)
yaml
的读取需要指定 Loader
的方式with open("yaml.yml", 'r') as f:test_ = yaml.load(f, Loader=yaml.FullLoader)
yaml和json区别
YAML vs. JSON: 有什么区别?
Python Yaml dump文件时中文显示解决方法
上一篇:C语言百日刷题第十二天