Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109288
| From | Peng Yu <pengyu.ut@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | How to print unicode characters with yaml.safe_dump()? |
| Date | 2016-05-31 11:58 -0500 |
| Message-ID | <mailman.56.1464713892.1839.python-list@python.org> (permalink) |
| References | <CABrM6wmj3Hi0ZxPCvsgBnSXuNk367jBbU70QDuOpJ7ZrUcbsKA@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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
How to print unicode characters with yaml.safe_dump()? Peng Yu <pengyu.ut@gmail.com> - 2016-05-31 11:58 -0500
csiph-web