From: Kirill S. <xi...@ga...> - 2007-12-26 13:50:36
|
Makoto Kuwata wrote: > I have question about encoding option of yaml.dump() of PyYAML. > > I tried the following python script, and got '"\u30DD\u30B1\u30E2\u30F3"' > as a result, thought what I expect is utf8 characters, not escaped sequence. > > import yaml > data = [u'\u30dd\u30b1\u30e2\u30f3'] > print yaml.dump(data, default_flow_style=False) > print yaml.dump(data, default_flow_style=False, encoding='utf8') > ## (result) > ## - "\u30DD\u30B1\u30E2\u30F3" > ## - "\u30DD\u30B1\u30E2\u30F3" > ## (expected) > ## - "\u30DD\u30B1\u30E2\u30F3" > ## - XXXX # japanese characters in utf8 > > Is it possible to get utf8 characters using yaml.dump() ? By default, PyYAML does not emit non-ASCII characters unescaped. You need to set the flag allow_unicode to print Japanese characters: print yaml.dump(data, default_flow_style=False, allow_unicode=True) Thanks, Kirill |