我使用pyyaml将一个对象转储到一个文件。对象中有几个unicode字符串。我以前也这样做过,但现在它产生的输出项如下:
'item': !!python/unicode "some string"
而不是期望的:
'item': 'some string'
我打算输出为utf-8。我当前使用的命令是:
yaml.dump(data,file(suite_out,'w'),encoding='utf-8',indent=4,allow_unicode=True)
在其他位置,我执行以下操作,并且它工作正常:
codecs.open(suite_out,"w","utf-8").write(
yaml.dump(suite,indent=4,width=10000)
)
我做错了什么?
Python 2.7.3
https://stackoverflow.com/questions/20352794
复制相似问题