我正在使用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
我尝试了很多组合,我能找到的唯一能够始终生成正确YAML输出的组合是:
yaml.safe_dump(data, file(filename,'w'), encoding='utf-8', allow_unicode=True)