Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin.stu.neva.ru!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'win32': 0.03; 'sys': 0.05; 'correspond': 0.07; 'see:': 0.07; 'python': 0.09; 'sep': 0.09; 'subject:error': 0.11; 'encoding': 0.15; 'subject:unicode': 0.16; 'wrongly': 0.16; 'wrote:': 0.17; 'copied': 0.17; 'thu,': 0.17; '>>>': 0.18; 'bit': 0.21; 'import': 0.21; 'displayed': 0.22; "skip:' 40": 0.22; 'this:': 0.23; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'skip:( 20': 0.28; 'run': 0.28; '>>>>': 0.29; 'no,': 0.29; 'window': 0.30; 'code': 0.31; "skip:' 20": 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'nov': 0.35; 'pm,': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'characters': 0.36; 'should': 0.36; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'nothing': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'more': 0.63; 'here': 0.65; '\xe2\x80\x93': 0.75; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=DDLmiPEsc6JLFcECamZS2J/3FJMbBnySiQDvI+QkoOI=; b=jGPBh/8DlXnbKl09Pakkw4voiSzFQfyRiBadSd/Kp8LknEMbHddCJvh6FcmWoBzGcW oW3FKV24O0pyBXi4XZLRMd1hvOugejOsY8RTELmN89auQ+bdYFQqzsa5ZRJrKo6PfJL6 FmtJjMHr/QAKvlohyNYxMU1nRYVyeEEB7QimbHrBWhXR0XRbAL4FBMcpWHPJMFnFhpmp 152Ua5wufpJE7wnkv4gKjZd5AwVmqAj+rUxHhRPP8IW4IJc3FURS/+ronnvf8283tijl 6WCSvZmBkWnVyM698F9zukWIUZW3nXWFcnl24apCMnGywSJFHjRHvoXJhPQBD9e6Jttb Kf0g== MIME-Version: 1.0 In-Reply-To: References: <09a3d20b-5871-47f4-9218-df119698e405@m4g2000yqf.googlegroups.com> <509AF3EF.8050108@gmail.com> <65910cea-f145-409c-a579-9f0cda499546@googlegroups.com> From: Ian Kelly Date: Thu, 8 Nov 2012 13:41:37 -0700 Subject: Re: Right solution to unicode error? To: Python Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352407330 news.xs4all.nl 6926 [2001:888:2000:d::a6]:44678 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32980 On Thu, Nov 8, 2012 at 12:54 PM, wrote: > Font has nothing to do here. > You are "simply" wrongly encoding your "unicode". > >>>> '\u2013' > '=E2=80=93' >>>> '\u2013'.encode('utf-8') > b'\xe2\x80\x93' >>>> '\u2013'.encode('utf-8').decode('cp1252') > '=C3=A2=E2=82=AC=E2=80=9C' No, it seriously is the font. This is what I get using the default ("Raster") font: C:\>chcp 65001 Active code page: 65001 C:\>c:\python33\python Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> '\u2013' '=C3=A2=E2=82=AC=E2=80=9C' >>> import sys >>> sys.stdout.buffer.write('\u2013\n'.encode('utf-8')) =C3=A2=E2=82=AC=E2=80=9C 4 I should note here that the characters copied and pasted do not correspond to the glyphs actually displayed in my terminal window. In the terminal window I actually see: =CE=93=C3=87=C3=B4 If I change the font to Lucida Console and run the *exact same code*, I get this: C:\>chcp 65001 Active code page: 65001 C:\>c:\python33\python Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> '\u2013' '=E2=80=93' >>> import sys >>> sys.stdout.buffer.write('\u2013\n'.encode('utf-8')) =E2=80=93 4 Why is the font important? I have no idea. Blame Microsoft.