【问题标题】:Dump in PyYaml as utf-8在 PyYaml 中转储为 utf-8
【发布时间】:2012-05-25 18:58:59
【问题描述】:

我正在尝试加载一堆 utf-8 编码的字符串并使用 PyYaml 再次转储它们。这是加载/转储的代码:

lang_yml = yaml.load(codecs.open(lang + ".yml.old", "r", "utf-8"))
test_file_path = lang + '.yml'
stream = file(test_file_path, 'w')
yaml.dump(lang_yml, stream,  default_flow_style=False, encoding=('utf-8'))

但是以“En arrière”开头的字符串最终会保存为“En arri\xE8re”。 我做错了什么?

【问题讨论】:

    标签: python utf-8 pyyaml


    【解决方案1】:

    自己找到了答案。我只需要把它和参数一起扔掉

    allow_unicode=True
    

    来源:http://dpinte.wordpress.com/2008/10/31/pyaml-dump-option/

    【讨论】:

      猜你喜欢
      • 2015-01-14
      • 2012-03-26
      • 2014-03-08
      • 2021-01-27
      • 2014-01-15
      • 2021-05-20
      • 1970-01-01
      • 2021-11-20
      相关资源
      最近更新 更多