Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'bug': 0.02; 'url:bugs': 0.05; 'received:verizon.net': 0.07; 'terry': 0.07; 'python': 0.08; '>>>>': 0.09; 'encodes': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'am,': 0.12; '2.7': 0.13; '"copyright",': 0.16; '"credits"': 0.16; '"license"': 0.16; '(none': 0.16; '2.7.2': 0.16; 'codec': 0.16; 'encode': 0.16; 'mbcs': 0.16; 'py3': 0.16; 'reedy': 0.16; 'wrote:': 0.18; 'jan': 0.19; '(most': 0.21; 'header:In-Reply-To:1': 0.22; 'sep': 0.23; 'traceback': 0.24; 'fix': 0.27; 'bit': 0.28; 'unicode': 0.29; "skip:' 10": 0.29; 'error': 0.29; 'correct': 0.29; "can't": 0.32; 'header:User-Agent:1': 0.33; 'header:X-Complaints-To:1': 0.33; 'done': 0.34; 'to:addr:python-list': 0.34; 'character': 0.34; 'last):': 0.34; 'url:python': 0.36; 'file': 0.36; 'skip:" 10': 0.37; 'doing': 0.38; 'received:org': 0.38; 'characters': 0.39; 'url:org': 0.39; 'to:addr:python.org': 0.40; 'more': 0.61; 'type': 0.61; 'according': 0.61; 'supposedly': 0.84; 'chinese': 0.85 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: UnicodeEncodeError in compile Date: Tue, 10 Jan 2012 19:56:39 -0500 References: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> <3c9fd9e7-6a0e-40cc-a048-1a82e477c013@p4g2000vbt.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-74-109-121-73.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 In-Reply-To: <3c9fd9e7-6a0e-40cc-a048-1a82e477c013@p4g2000vbt.googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1326243425 news.xs4all.nl 6875 [2001:888:2000:d::a6]:59701 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18790 On 1/10/2012 8:43 AM, jmfauth wrote: > D:\>c:\python32\python.exe > Python 3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit > (Intel)] on win > 32 > Type "help", "copyright", "credits" or "license" for more information. >>>> '\u5de5'.encode('utf-8') > b'\xe5\xb7\xa5' >>>> '\u5de5'.encode('mbcs') > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'mbcs' codec can't encode characters in position > 0--1: inval > id character > D:\>c:\python27\python.exe > Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit > (Intel)] on win > 32 > Type "help", "copyright", "credits" or "license" for more information. >>>> u'\u5de5'.encode('utf-8') > '\xe5\xb7\xa5' >>>> u'\u5de5'.encode('mbcs') > '?' mbcs encodes according to the current codepage. Only the chinese codepage(s) can encode the chinese char. So the unicode error is correct and 2.7 has a bug in that it is doing "errors='replace'" when it supposedly is doing "errors='strict'". The Py3 fix was done in http://bugs.python.org/issue850997 2.7 was intentionally left alone because of back-compatibility considerations. (None of this addresses the OP's question.) -- Terry Jan Reedy