with open('data.yaml', 'w', encoding='utf-8') as file:
yaml.dump(list1, file, sort_keys=False, allow_unicode=True)
其中,encoding='utf-8'
表示输出文件的编码格式为 UTF-8,allow_unicode=True
表示允许输出 Unicode 字符。这样就可以避免输出的中文乱码问题。
with open('data.yaml', 'w', encoding='utf-8') as file:
yaml.dump(list1, file, sort_keys=False, allow_unicode=True)
其中,encoding='utf-8'
表示输出文件的编码格式为 UTF-8,allow_unicode=True
表示允许输出 Unicode 字符。这样就可以避免输出的中文乱码问题。