How to print unicode characters with yaml.safe_dump()?

Peng Yu <[email protected]> Tue, 31 May 2016 12:08:56 -0500
Newsgroups gmane.text.yaml.general
Message-ID <CABrM6wmOMedzoSTx2S16DyhEAXkfUpoaQM32jmO6e57-xPNOwA@mail.gmail.com>
Hi, The following code shows that "Michał" is printed differently for
print(yaml.safe_dump(...)) and the direct print. Does anybody know how
to use yaml.safe_dump() so that "Michał" will be printed as is.

~$ cat main.py
#!/usr/bin/env python
# vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8:

import yaml

foo = {
    u'first': u"Michał",
    u'last': u"Seweryn",
}

print foo['first']

print(yaml.safe_dump(foo, default_flow_style=True).encode('utf-8'))
print(yaml.safe_dump(foo, default_flow_style=False).encode('utf-8'))
~$ ./main.py
Michał
{first: "Micha\u0142", last: Seweryn}

first: "Micha\u0142"
last: Seweryn

--
Regards,
Peng

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Yaml-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/yaml-core