Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109288
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Peng Yu <pengyu.ut@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | How to print unicode characters with yaml.safe_dump()? |
| Date | Tue, 31 May 2016 11:58:10 -0500 |
| Lines | 30 |
| Message-ID | <mailman.56.1464713892.1839.python-list@python.org> (permalink) |
| References | <CABrM6wmj3Hi0ZxPCvsgBnSXuNk367jBbU70QDuOpJ7ZrUcbsKA@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | news.uni-berlin.de NlXwctykJHyRSi0CqBs9zQAUTBG6vMODenUkUmu0i35g== |
| Return-Path | <pengyu.ut@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'differently': 0.07; 'subject:How': 0.09; 'subject:characters': 0.09; 'received:209.85.218': 0.10; 'python': 0.10; 'first:': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:unicode': 0.16; 'yaml': 0.16; 'to:name:python-list@python.org': 0.20; 'import': 0.24; 'skip:# 10': 0.27; 'message-id:@mail.gmail.com': 0.27; 'cat': 0.29; 'print': 0.30; 'code': 0.30; 'anybody': 0.32; 'skip:d 40': 0.32; 'foo': 0.33; 'received:google.com': 0.35; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'received:209': 0.38; 'skip:p 20': 0.38; 'hi,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'is.': 0.63; 'direct': 0.68 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to :content-transfer-encoding; bh=OJXbrzTFbH1w4Kawx9i8UUYkHR6NxbecF+o3VfXclbQ=; b=eT7yqhEQ0NSMEDmRv0FMSUXjNw4xJ+6j8McqUNjfgQrR4AoaZpPnMWuNx/VN6CXlyy 8hnGh4Gm8jiimuA6B4K0fTv7uSmZWsBhWUCkaCdAtSRtp83gSQFBU8ByNEoiiNorVL5+ 3PFudPHmnhmEXTFmGS1ZeRmPuEl0g9o7ialj6lNL7jMORpLkSRBW4Qc3+XaxgRLKLMDK KIHPbPsDxNcZJD3ZqLCcd7pe/VeW8jHCic5RVjIpGatGvDo8twxPcTLK4aPeVCWkmA5w HogesYBHAjVov9+1uNQE0ibyn5Xq1CebBxaPGKqqtJkVzgbQEUbqQO6M1OibghdnGf+z z9Tw== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-transfer-encoding; bh=OJXbrzTFbH1w4Kawx9i8UUYkHR6NxbecF+o3VfXclbQ=; b=DU38YQS4xo+KJUp3pamR5S4fefvjS16rEGzYA4I3BruvHyuVkBUv7KesmZMEofYZbA Z1WEFSK1UN9BdoI5seT/ms6XKQKUPTaFm7k6XEd0W6Y9bSgxJQRNi4GLdVevgHHcVEW2 /ZrobLDFZALJRnkt8K6BqKy/qKgGVskVAkg57X/pohKPLYueohWsSGzp+v2mVIGA/Tv/ Cjy+rLUk6Xf6wMxhpT+WUX5KD7H8uVEuOMm4jXBTtYtbL5qvuMsY/lz/ZRxlPy/5Nwjq nmMgN8ZBv/Kj8kf5CDuKBFbVVxwfg/IS9OkA9kxuFrmPFb5KlYJ0QPw9PeoDiX6OLaX/ 6eeg== |
| X-Gm-Message-State | ALyK8tJLyg/WUC6gi9KkUxjZhACvPMGzL4D78ztr4Q1NXCpF/5UpRchem8Lk+bCVwJEgyqVF+4g6nMZy5zL0/w== |
| X-Received | by 10.157.45.129 with SMTP id g1mr590192otb.57.1464713890709; Tue, 31 May 2016 09:58:10 -0700 (PDT) |
| 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 | <CABrM6wmj3Hi0ZxPCvsgBnSXuNk367jBbU70QDuOpJ7ZrUcbsKA@mail.gmail.com> |
| Xref | csiph.com comp.lang.python:109288 |
Show key headers only | View raw
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