Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Peng Yu 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: References: 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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: Xref: csiph.com comp.lang.python:109288 Hi, The following code shows that "Micha=C5=82" is printed differently for print(yaml.safe_dump(...)) and the direct print. Does anybody know how to use yaml.safe_dump() so that "Micha=C5=82" will be printed as is. ~$ cat main.py #!/usr/bin/env python # vim: set noexpandtab tabstop=3D2 shiftwidth=3D2 softtabstop=3D-1 fileenco= ding=3Dutf-8: import yaml foo =3D { u'first': u"Micha=C5=82", u'last': u"Seweryn", } print foo['first'] print(yaml.safe_dump(foo, default_flow_style=3DTrue).encode('utf-8')) print(yaml.safe_dump(foo, default_flow_style=3DFalse).encode('utf-8')) ~$ ./main.py Micha=C5=82 {first: "Micha\u0142", last: Seweryn} first: "Micha\u0142" last: Seweryn --=20 Regards, Peng