Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.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.040 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'insert': 0.05; 'character,': 0.09; 'subject:2.7': 0.09; "''.join(c": 0.16; '-tkc': 0.16; 'distinct': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'received:10.216': 0.16; 'subject:unicode': 0.16; 'subject:python': 0.16; 'weird': 0.16; 'wrote:': 0.18; 'example': 0.22; 'this?': 0.23; 'string,': 0.24; 'unicode': 0.24; 'looks': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'character': 0.29; 'characters': 0.30; 'code': 0.31; "skip:' 10": 0.31; "d'aprano": 0.31; 'steven': 0.31; 'text': 0.33; 'subject:time': 0.33; 'sense': 0.34; 'subject: (': 0.35; 'display': 0.35; 'something': 0.35; 'form.': 0.35; 'test': 0.35; 'but': 0.35; 'combination': 0.36; 'subject:one': 0.36; 'should': 0.36; 'application': 0.37; 'two': 0.37; 'received:10': 0.37; 'handle': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'even': 0.60; 'remove': 0.60; 'middle': 0.60; 'happen': 0.63; 'skip:n 10': 0.64; 'subject:more': 0.64; 'received:46': 0.66; 'combining': 0.68; 'as:': 0.81; 'perspective,': 0.84; 'routines': 0.84; 'canonical': 0.91 X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-MC-Relay: Neutral X-MailChannels-SenderId: wwwh|x-authuser|tim@thechases.com X-MailChannels-Auth-Id: wwwh X-MC-Loop-Signature: 1416585453458:1381203137 X-MC-Ingress-Time: 1416585453458 Date: Fri, 21 Nov 2014 10:00:10 -0600 From: Tim Chase To: python-list@python.org Subject: Re: python 2.7 and unicode (one more time) In-Reply-To: <546f58db$0$12990$c3e8da3$5496439d@news.astraweb.com> References: <1416491999.209592.193345213.3A6FF9A4@webmail.messagingengine.com> <87ppch8zvx.fsf@elektro.pacujo.net> <546e880d$0$12995$c3e8da3$5496439d@news.astraweb.com> <546f58db$0$12990$c3e8da3$5496439d@news.astraweb.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-AuthUser: tim@thechases.com 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: 60 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416585466 news.xs4all.nl 2910 [2001:888:2000:d::a6]:55035 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81218 On 2014-11-22 02:23, Steven D'Aprano wrote: > LATIN SMALL LETTER E > COMBINING CIRCUMFLEX ACCENT >=20 > then my application should treat that as a single "character" and > display it as: >=20 > LATIN SMALL LETTER E WITH CIRCUMFLEX >=20 > which looks like this: =C3=AA >=20 > rather than two distinct "characters" e=CB=86 >=20 > Now, that specific example is a no-brainer, because the Unicode > normalization routines will handle the conversion. But not every > combination of accented characters has a canonical combined form. > What about something like this? >=20 > 'w\N{COMBINING CIRCUMFLEX ACCENT}\N{COMBINING OGONEK}\N{COMBINING > CARON}' >=20 > If I insert a character into my string, I want to be able to insert > before the w or after the caron, but not in the middle of those > three code points. Things get even weirder if you have '\N{LATIN SMALL LETTER E WITH CIRCUMFLEX}\N{COMBINING OGONEK}\N{COMBINING CARON}' and when you try to do comparisons like s1 =3D '\N{LATIN SMALL LETTER E WITH CIRCUMFLEX}\N{COMBINING OGONEK}' s2 =3D 'e\N{COMBINING CIRCUMFLEX ACCENT}\N{COMBINING OGONEK}' s3 =3D 'e\N{COMBINING OGONEK}\N{COMBINING CIRCUMFLEX ACCENT}' print(s1 =3D=3D s2) print(s1 =3D=3D s3) print(s2 =3D=3D s3) Then you also have the case where you want to edit text and the user wants to remove the COMBINING OGONEK from the character, so you *do* want to do something akin to s4 =3D ''.join(c for c in s3 if c !=3D '\N{COMBINING OGONEK}') And yet, weird things happen if you try to remove the circumflex: for test in (s1, s2, s3): print(test =3D=3D ''.join( c for c in test if c !=3D '\N{COMBINING CIRCUMFLEX ACCENT}' ) They all make sense if you understand what's going on under the hood, but from a visual/conceptual perspective, something feels amiss. -tkc