Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33040
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.008 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'python': 0.09; 'byte,': 0.09; 'delimiter': 0.09; 'encode': 0.09; 'subject:characters': 0.09; '10:17': 0.16; 'codec': 0.16; 'string': 0.17; 'wrote:': 0.17; 'byte': 0.17; 'unicode': 0.17; 'app': 0.19; 'skip:" 30': 0.20; 'errors': 0.23; 'header:In-Reply-To:1': 0.25; 'skip:" 20': 0.26; '(most': 0.27; 'am,': 0.27; 'converting': 0.27; 'instead.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'fine': 0.28; 'character': 0.29; 'convert': 0.29; "i'm": 0.29; 'fri,': 0.30; 'received:209.85.215.46': 0.30; 'error': 0.30; 'code': 0.31; 'point': 0.31; 'file': 0.32; 'traceback': 0.33; 'to:addr:python- list': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'exist': 0.35; 'nov': 0.35; 'received:209.85': 0.35; 'really': 0.36; 'does': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'application': 0.40; 'header:Received:5': 0.40; 'skip:u 10': 0.60; 'skip:c 50': 0.66; '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=dvkq8GHV3DIHGpDOyvujsEPgrebClW4VYQwAWKDlh1Q=; b=k4D+T+R6opgJ/yn84aERDNJ5/hNa6qzWOdDIjgDdNbQQY4YakStPk6QXi98JV2a6Fu rRIHPCrnv/But6E8LIadQ49GEW5V+NoN2lJZYyDI9BiXKPBcheW+x/v5AxXdAceZ0rVg bYiAJ5c5EPuT+iYHEAn+mH5SgisWaBz+/8H3PN2/lA1WUxMJmkvClMhxJE+rQtXtZxZ8 3ViGnwVdimq8rK8Ni5qzOIPqagmKd2GhptCLjVzQ4NCA588+TgEZvwDGz/5NZ/cwiGue 2kLXBiIKK37JXQ15qat2ch8S4oVdarueMh49I8gVFay5IgJ0tCJ0bEnVjqP8XrFVm6Mz WVvg== |
| MIME-Version | 1.0 |
| In-Reply-To | <3d4644f8-ab88-41c5-9a52-2a5678dd64c0@googlegroups.com> |
| References | <3d4644f8-ab88-41c5-9a52-2a5678dd64c0@googlegroups.com> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Fri, 9 Nov 2012 10:34:51 -0700 |
| Subject | Re: Printing characters outside of the ASCII range |
| To | Python <python-list@python.org> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| 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 <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3505.1352482524.27098.python-list@python.org> (permalink) |
| Lines | 31 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1352482524 news.xs4all.nl 6952 [2001:888:2000:d::a6]:58251 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:33040 |
Show key headers only | View raw
On Fri, Nov 9, 2012 at 10:17 AM, danielk <danielkleinad@gmail.com> wrote: > I'm converting an application to Python 3. The app works fine on Python 2. > > Simply put, this simple one-liner: > > print(chr(254)) > > errors out with: > > Traceback (most recent call last): > File "D:\home\python\tst.py", line 1, in <module> > print(chr(254)) > File "C:\Python33\lib\encodings\cp437.py", line 19, in encode > return codecs.charmap_encode(input,self.errors,encoding_map)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\xfe' in position 0: character maps to <undefined> > > I'm using this character as a delimiter in my application. > > What do I have to do to convert this string so that it does not error out? In Python 2, chr(254) means the byte 254. In Python 3, chr(254) means the Unicode character with code point 254, which is "รพ". This character does not exist in CP 437, so it fails to encode it for output. If what you really want is the byte, then use b'\xfe' or bytes([254]) instead.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Printing characters outside of the ASCII range danielk <danielkleinad@gmail.com> - 2012-11-09 09:17 -0800
Re: Printing characters outside of the ASCII range Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-09 10:34 -0700
Re: Printing characters outside of the ASCII range Andrew Berg <bahamutzero8825@gmail.com> - 2012-11-09 11:39 -0600
Re: Printing characters outside of the ASCII range Dave Angel <d@davea.name> - 2012-11-09 12:47 -0500
Re: Printing characters outside of the ASCII range danielk <danielkleinad@gmail.com> - 2012-11-09 13:17 -0800
RE: Printing characters outside of the ASCII range "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-11-09 21:34 +0000
Re: Printing characters outside of the ASCII range danielk <danielkleinad@gmail.com> - 2012-11-09 13:46 -0800
Re: Printing characters outside of the ASCII range Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-09 15:10 -0700
Re: Printing characters outside of the ASCII range danielk <danielkleinad@gmail.com> - 2012-11-11 05:42 -0800
Re: Printing characters outside of the ASCII range Lele Gaifax <lele@metapensiero.it> - 2012-11-11 18:09 +0100
Re: Printing characters outside of the ASCII range danielk <danielkleinad@gmail.com> - 2012-11-11 05:42 -0800
Re: Printing characters outside of the ASCII range danielk <danielkleinad@gmail.com> - 2012-11-09 13:46 -0800
Re: Printing characters outside of the ASCII range Andrew Berg <bahamutzero8825@gmail.com> - 2012-11-09 15:39 -0600
Re: Printing characters outside of the ASCII range danielk <danielkleinad@gmail.com> - 2012-11-09 13:17 -0800
Re: Printing characters outside of the ASCII range wxjmfauth@gmail.com - 2012-11-10 02:09 -0800
Re: Printing characters outside of the ASCII range Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-11-11 15:40 +0100
csiph-web