Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33042

Re: Printing characters outside of the ASCII range

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <bahamutzero8825@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'received:209.85.223': 0.03; 'cpython': 0.05; 'python': 0.09; 'delimiter': 0.09; 'encode': 0.09; 'subject:characters': 0.09; 'assume': 0.11; 'encoding': 0.15; 'weird': 0.15; 'codec': 0.16; 'idle,': 0.16; 'string': 0.17; 'wrote:': 0.17; 'systems.': 0.18; 'windows': 0.19; 'app': 0.19; 'skip:" 30': 0.20; 'errors': 0.23; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:" 20': 0.26; '(most': 0.27; 'converting': 0.27; 'replace': 0.27; 'fine': 0.28; 'character': 0.29; 'convert': 0.29; 'probably': 0.29; "i'm": 0.29; 'error': 0.30; 'code': 0.31; 'file': 0.32; 'traceback': 0.33; 'to:addr:python-list': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'received:209.85': 0.35; 'something': 0.35; 'message- id:@gmail.com': 0.36; 'does': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'supports': 0.38; 'page': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'application': 0.40; 'received:192.168': 0.40; 'header:Received:5': 0.40; 'skip:u 10': 0.60; 'skip:6 10': 0.63; 'different': 0.63; 'subject': 0.66; 'skip:c 50': 0.66; "(don't": 0.84; 'graphical': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; bh=F7qya/U3h2wWoSwgSywgW+eTAAl66ZdGEyZpa3XAPNI=; b=pWlH8vAaLwciU8YkyG7WrCBFKQ5k7iw1AmiCnj0AcZv959CbmTfoAMHntnBTzEq+f3 vqMiWpxQufPUqUEpR2WwOL3CAitn1C63BXgfS8Pm8ziydDxATCxFAwjWEaM3cXxtBFko FuLl/6JjJIRooF8kdbq7mPCs36DIUUSrdQrBH8hn4p/BZmzZFGHeHnyhOwfwFBCFTXec KmwSdlAd3esfR7GdDYVJCjVk0x9aI4rFGo+7lwuRAOyaFU/IpKjopzQxkx4N2jIRdIb9 SZdMESooprM7r6aP7Lgm+miIiQeIFYydtEMrTao5rkYt4JH7cnorh5aZxYUppl76eHU5 ghJA==
Date Fri, 09 Nov 2012 11:39:50 -0600
From Andrew Berg <bahamutzero8825@gmail.com>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20121026 Thunderbird/16.0.2
MIME-Version 1.0
To "comp.lang.python" <python-list@python.org>
Subject Re: Printing characters outside of the ASCII range
References <3d4644f8-ab88-41c5-9a52-2a5678dd64c0@googlegroups.com>
In-Reply-To <3d4644f8-ab88-41c5-9a52-2a5678dd64c0@googlegroups.com>
X-Enigmail-Version 1.4.5
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
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.3507.1352482800.27098.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1352482800 news.xs4all.nl 6866 [2001:888:2000:d::a6]:34751
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:33042

Show key headers only | View raw


On 2012.11.09 11:17, danielk 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?
> 
That character is outside of cp437 - the default terminal encoding on
many Windows systems. You will either need to change the code page to
something that supports the character (if you're going to change it, you
might as well change it to cp65001 since you are using 3.3), catch the
error and replace the character with something that is in the current
codepage (don't assume cp437; it is not the default everywhere), or use
a different character completely. If it works on Python 2, it's probably
changing the character automatically to a replacement character or you
were using IDLE, which is graphical and is not subject to the weird
encoding system of terminals.
-- 
CPython 3.3.0 | Windows NT 6.1.7601.17835

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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