Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!feed.xsnews.nl!border-1.ams.xsnews.nl!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; 'currency': 0.07; 'utf-8': 0.07; 'subject:How': 0.09; 'python': 0.09; 'adopted': 0.09; 'charset': 0.09; 'codecs': 0.09; 'encode': 0.09; 'parsed': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:()': 0.09; 'subject:string': 0.09; 'subject:using': 0.09; 'terry': 0.09; 'read.': 0.13; '(the': 0.15; 'encoding': 0.15; '1985': 0.16; '1992.': 0.16; 'apostrophes': 0.16; 'codec': 0.16; 'examples:': 0.16; 'ordinal': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'sign.': 0.16; 'subject: \n ': 0.16; 'subject:unicode': 0.16; 'subject:variable': 0.16; 'task.': 0.16; 'unneeded': 0.16; 'wrote:': 0.17; 'byte': 0.17; 'fixed.': 0.17; 'unicode': 0.17; 'jan': 0.18; 'windows': 0.19; '"",': 0.22; 'accommodate': 0.22; 'browsers': 0.22; 'lets': 0.22; 'seems': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'common': 0.26; 'url:wiki': 0.26; '(most': 0.27; '(see': 0.27; 'wonder': 0.27; 'question': 0.27; 'label': 0.27; 'correct': 0.28; 'header:X-Complaints-To:1': 0.28; '>>>>': 0.29; 'url:wikipedia': 0.29; 'character': 0.29; '"the': 0.29; 'push': 0.30; 'standards': 0.30; 'code': 0.31; 'december': 0.32; 'file': 0.32; 'mac': 0.32; "skip:' 20": 0.32; 'advertised': 0.33; 'dates': 0.33; 'instead,': 0.33; 'quotes': 0.33; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'version': 0.34; "can't": 0.34; 'changed': 0.34; 'text': 0.34; 'generic': 0.35; 'mapping': 0.35; 'replaced': 0.35; 'pm,': 0.35; "won't": 0.35; 'something': 0.35; 'received:org': 0.36; 'url:org': 0.36; 'apple': 0.36; 'others.': 0.36; 'too': 0.36; 'operating': 0.36; 'bad': 0.37; 'does': 0.37; 'communicate': 0.37; 'systems,': 0.37; 'previous': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'url:en': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'easy': 0.60; 'skip:u 10': 0.60; 'most': 0.61; 'chance': 0.61; 'relatively': 0.62; 'email addr:gmail.com': 0.63; 'more': 0.63; 'behavior': 0.64; 'making': 0.64; 'great': 0.64; 'choose': 0.65; 'else.': 0.65; 'producers': 0.65; 'treat': 0.65; 'believe': 0.69; 'euro': 0.69; 'published': 0.71; '"smart': 0.84; 'received:fios.verizon.net': 0.84; 'subject:value': 0.84; '"it': 0.91; 'officially': 0.91; '1988': 0.93; 'hundred': 0.95 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: How do I display unicode value stored in a string variable using ord() Date: Sun, 19 Aug 2012 17:59:43 -0400 References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <28f35cee-3e55-43af-afc8-1ded199c53d9@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0 In-Reply-To: <28f35cee-3e55-43af-afc8-1ded199c53d9@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: 56 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1345413613 news.xs4all.nl 6961 [2001:888:2000:d::a6]:58342 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27436 On 8/19/2012 2:11 PM, wxjmfauth@gmail.com wrote: > Well, it seems some software producers know what they > are doing. > >>>> '=E2=82=AC'.encode('cp1252') > b'\x80' >>>> '=E2=82=AC'.encode('mac-roman') > b'\xdb' >>>> '=E2=82=AC'.encode('iso-8859-1') > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'latin-1' codec can't encode character '\u20ac' > in position 0: ordinal not in range(256) Yes, Python lets you choose your byte encoding from those and a hundred=20 others. I believe all the codecs are now tested in both directions. It=20 was not an easy task. As to the examples: Latin-1 dates to 1985 and before and the 1988=20 version was published as a standard in 1992. https://en.wikipedia.org/wiki/Latin-1 "The name euro was officially adopted on 16 December 1995." https://en.wikipedia.org/wiki/Euro No wonder Latin-1 does not contain the Euro sign. International=20 standards organizations standards are relatively fixed. (The unicode=20 consortium will not even correct misspelled character names.) Instead,=20 new standards with a new number are adopted. For better or worse, private mappings are more flexible. In its Mac=20 mapping Apple "replaced the generic currency sign =C2=A4 with the euro si= gn=20 =E2=82=AC". (See Latin-1 reference.) Great if you use Euros, not so great= if you=20 were using the previous sign for something else. Microsoft changed an unneeded code to the Euro for Windows cp-1252. https://en.wikipedia.org/wiki/Windows-1252 "It is very common to mislabel Windows-1252 text with the charset label=20 ISO-8859-1. A common result was that all the quotes and apostrophes=20 (produced by "smart quotes" in Microsoft software) were replaced with=20 question marks or boxes on non-Windows operating systems, making text=20 difficult to read. Most modern web browsers and e-mail clients treat the = MIME charset ISO-8859-1 as Windows-1252 in order to accommodate such=20 mislabeling. This is now standard behavior in the draft HTML 5=20 specification, which requires that documents advertised as ISO-8859-1=20 actually be parsed with the Windows-1252 encoding.[1]" Lots of fun. Too bad Microsoft won't push utf-8 so we can all=20 communicate text with much less chance of ambiguity. --=20 Terry Jan Reedy