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: 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 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" 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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 > 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 > > 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