Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109289
| Path | csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed0.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Peter Otten <__peter__@web.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: How to print unicode characters with yaml.safe_dump()? |
| Date | Tue, 31 May 2016 19:38:31 +0200 |
| Organization | None |
| Lines | 37 |
| Message-ID | <mailman.57.1464716322.1839.python-list@python.org> (permalink) |
| References | <CABrM6wmj3Hi0ZxPCvsgBnSXuNk367jBbU70QDuOpJ7ZrUcbsKA@mail.gmail.com> <niki6o$2dk$1@ger.gmane.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Trace | news.uni-berlin.de nFhsyxZ0Eo0Fe+1uimexNQiMZ3dqk/YRdokssQftFllg== |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'differently': 0.07; 'subject:How': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:characters': 0.09; 'python': 0.10; 'first:': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:unicode': 0.16; 'yaml': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'import': 0.24; 'header:User-Agent:1': 0.26; 'header:X -Complaints-To:1': 0.26; 'skip:# 10': 0.27; 'cat': 0.29; 'print': 0.30; 'code': 0.30; 'anybody': 0.32; 'skip:d 40': 0.32; 'foo': 0.33; 'skip:d 20': 0.34; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'skip:p 20': 0.38; 'hi,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'received:de': 0.40; 'is.': 0.63; 'direct': 0.68 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | p57bd8584.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <niki6o$2dk$1@ger.gmane.org> |
| X-Mailman-Original-References | <CABrM6wmj3Hi0ZxPCvsgBnSXuNk367jBbU70QDuOpJ7ZrUcbsKA@mail.gmail.com> |
| Xref | csiph.com comp.lang.python:109289 |
Show key headers only | View raw
Peng Yu wrote:
> 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
>
Use the allow_unicode flag:
>>> print yaml.safe_dump(foo, allow_unicode=True, default_flow_style=False)
first: Michał
last: Seweryn
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: How to print unicode characters with yaml.safe_dump()? Peter Otten <__peter__@web.de> - 2016-05-31 19:38 +0200
csiph-web