Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone01.am1.xlned.com!bcyclone01.am1.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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; 'scripts': 0.03; 'encoding': 0.05; 'remind': 0.05; '21,': 0.07; 'lines,': 0.07; 'plenty': 0.07; 'utf-8': 0.07; 'string': 0.09; 'ascii': 0.09; 'chunk': 0.09; 'covered.': 0.09; 'editor.': 0.09; 'handful': 0.09; 'insertion': 0.09; 'string;': 0.09; 'subject:2.7': 0.09; 'sure,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'systems.': 0.12; 'translation': 0.12; '11:32': 0.16; 'alphabet': 0.16; 'ascii,': 0.16; 'bytes).': 0.16; 'copying.': 0.16; 'doing,': 0.16; 'encoding.': 0.16; 'encodings': 0.16; 'encodings,': 0.16; 'finite': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'immutable,': 0.16; 'ought': 0.16; 'progressive': 0.16; 'speaker.': 0.16; 'subject:unicode': 0.16; 'such,': 0.16; 'sure.': 0.16; 'trivially': 0.16; 'unicode,': 0.16; 'unicode.': 0.16; 'unicode?': 0.16; '\xd0\xbd\xd0\xb5': 0.16; 'subject:python': 0.16; 'language': 0.16; 'wrote:': 0.18; 'have:': 0.19; 'normally': 0.19; 'pieces': 0.19; 'fit': 0.20; 'otherwise,': 0.22; 'cc:addr:python.org': 0.22; "aren't": 0.24; 'byte': 0.24; 'certainly': 0.24; 'space.': 0.24; 'text,': 0.24; 'unicode': 0.24; 'fairly': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'possibly': 0.26; 'speakers': 0.26; 'this:': 0.26; 'least': 0.26; 'supported': 0.26; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; 'am,': 0.29; 'array': 0.29; 'character': 0.29; 'characters': 0.30; 'sets': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; 'code': 0.31; 'lines': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'symbolic': 0.31; 'though.': 0.31; 'wind': 0.31; 'file': 0.32; 'probably': 0.32; 'compatible': 0.32; 'covered': 0.32; 'handled': 0.32; 'languages': 0.32; 'text': 0.33; '(e.g.': 0.33; 'fri,': 0.33; 'subject:time': 0.33; 'used,': 0.33; 'could': 0.34; 'problem': 0.35; 'subject: (': 0.35; "can't": 0.35; 'except': 0.35; 'something': 0.35; 'point.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'disk': 0.36; 'european': 0.36; 'largely': 0.36; 'representing': 0.36; 'skip:\xd0 10': 0.36; 'subject:one': 0.36; 'possible': 0.36; 'should': 0.36; 'example,': 0.37; 'application': 0.37; 'too': 0.37; 'easily': 0.37; 'myself': 0.63; 'skip:n 10': 0.64; 'our': 0.64; 'subject:more': 0.64; 'zip': 0.64; 'more': 0.64; 'different': 0.65; 'great': 0.65; 'needing': 0.65; 'worth': 0.66; 'world': 0.66; 'between': 0.67; 'natural': 0.68; 'debate': 0.68; 'difficulty': 0.68; 'eastern': 0.68; 'containing': 0.69; 'fact,': 0.69; 'saving': 0.69; '8bit%:92': 0.71; '8bit%:100': 0.72; 'bmp,': 0.84; 'boxes.': 0.84; 'different.': 0.84; 'finns': 0.84; 'points,': 0.84; 'russian,': 0.84; 'sky': 0.84; 'western': 0.86; 'to:none': 0.92; 'lucky': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=xiFey7RErF9b25tluqAQPE0qgvlFakuu5hOop4W6Prg=; b=lyt2N894MZdenIiK+cpRL5kXHRGBb6MUtZcQ+9Zj79DqQ+LTBzClheT8pEApje1S1+ kw48sxkL0SFK44JoDBRbch/Ayhi1FKTwEEPQE8Vg8ofSF3eVwFDtNgvmQJdzmBuc5v8R 5JsMljLqQMxAy5uUEtiEfJZzenMyymR8kXrEkgba2l1mHDEjy0hYMzxsFKWlLMYOVlDY 2ol6tPS0huo/zy5pxg0zlNqNt7S7Vt/ICVdIMzq4z+3/sQyAqhrr4xW+j8EW8NU33Svu iR9l7IuLJOus3tGfsElpiUrOnoIFt/gcKxp2bYeSiS06+wV6XHpY3fREe5WXNDqafVrs Lq3Q== MIME-Version: 1.0 X-Received: by 10.42.106.12 with SMTP id x12mr10586788ico.26.1416532212504; Thu, 20 Nov 2014 17:10:12 -0800 (PST) In-Reply-To: <546e880d$0$12995$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> Date: Fri, 21 Nov 2014 12:10:12 +1100 Subject: Re: python 2.7 and unicode (one more time) From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 129 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416532215 news.xs4all.nl 2953 [2001:888:2000:d::a6]:55845 X-Complaints-To: abuse@xs4all.nl X-Received-Body-CRC: 2989145346 X-Received-Bytes: 11016 Xref: csiph.com comp.lang.python:81156 On Fri, Nov 21, 2014 at 11:32 AM, Steven D'Aprano wrote: > (E.g. there are millions of existing files across the world containing te= xt > which use legacy encodings that are not compatible with Unicode.) Not compatible with Unicode? There aren't many character sets out there that include characters not in Unicode - that was the whole point. Of course, there are plenty of files in unspecified eight-bit encodings, so you may have a problem with reliable decoding - but if you know what the encoding is, you ought to be able to represent each character in Unicode. Not compatible with any of the UTFs, that's different. Plenty of that in the world. > You are certainly correct that in it's full generality, "text" is much mo= re > than just a string of code points. Unicode strings is a primitive data > type. A powerful and sophisticated text processing application may even > find Python strings too primitive, possibly needing something like ropes = of > graphemes rather than strings of code points. That's probably more an efficiency point, though. It should be possible to do a perfect two-way translation between your grapheme rope and a Python string; otherwise, you'll have great difficulty saving your file to the disk (which will normally involve representing the text in Unicode, then encoding that to bytes). To be sure, a Python string is a poor representational form for a text editor. But that's largely because it's immutable, so every little edit would involve massive copying. Depending on what you're doing, it might be worth using a chunked UTF-8 byte stream (allowing for insertion at any chunk boundary), or an array of lines, or something grapheme-based... but all of those questions are performance, not correctness, issues. > We Western and Northern European speakers -- and I don't know whether Fin= ns > are counted as Northern Europeans or Eastern Europeans -- are lucky in th= at > our natural languages are well-covered by Unicode. All our graphemes are > also code points, even the "funny ones with accents". As an English > speaker. I have to remind myself that not every grapheme is a single code > point, but Devanagari or Navajo writers will never make that mistake. I've been working with different languages a bit, lately. Broadly speaking, you have: 1) Languages which use the Roman alphabet, plus a handful of other characters (eg Finnish, German). These can be represented largely in ASCII, and used to be handled fairly easily with a single codepage - an eight-bit ASCII-compatible encoding. 2) Languages which use a different alphabet (eg Cyrillic - Russian, Bulgarian). You could possibly cram them into an eight-bit encoding without tipping ASCII out, but I'm not sure. In Unicode, these languages are all easily supported by the BMP, as they don't use a huge number of characters each. 3) Languages which use a non-alphabetic system (eg Korean). I think they're all still covered by the BMP, but there's no way you can fit them into eight-bit encodings - one single language will use more than 256 symbols. 4) Ancient, esoteric, or symbolic writing systems. Not fundamentally different from the above categories except that they're less used, and the BMP has finite space. These will definitely need the SMP. But all of them are covered by Unicode. (Sadly, they are NOT all covered by all fonts, so I've been finding that certain pieces of text come out as strings of little boxes. But I can at least manipulate the text, even if I can't read it back.) I can, for example, zip lines of text like this: English: Let it go, let it go! I am one with the wind and sky Let it go, let it go! You'll never see me cry! Icelandic: =C3=9Eetta er n=C3=B3g, =C3=BEetta er n=C3=B3g Uppi =C3=AD himni eins og vindabl=C3=A6r =C3=9Eetta er n=C3=B3g, komi=C3=B0 n=C3=B3g Og t=C3=A1r m=C3=ADn enginn s=C3=A9r f=C3=A6r Russian: =D0=9E=D1=82=D0=BF=D1=83=D1=81=D1=82=D0=B8 =D0=B8 =D0=B7=D0=B0=D0=B1=D1=83= =D0=B4=D1=8C, =D0=AD=D1=82=D0=BE=D1=82 =D0=BC=D0=B8=D1=80 =D0=B8=D0=B7 =D1=82=D0=B2=D0=BE= =D0=B8=D1=85 =D0=B3=D1=80=D1=91=D0=B7. =D0=9E=D1=82=D0=BF=D1=83=D1=81=D1=82=D0=B8 =D0=B8 =D0=B7=D0=B0=D0=B1=D1=83= =D0=B4=D1=8C, =D0=98 =D0=BD=D0=B5 =D0=B1=D1=83=D0=B4=D0=B5=D1=82 =D0=B1=D0=BE=D0=BB=D1=8C= =D1=88=D0=B5 =D1=81=D0=BB=D1=91=D0=B7. Output: Let it go, let it go! =C3=9Eetta er n=C3=B3g, =C3=BEetta er n=C3=B3g =D0=9E=D1=82=D0=BF=D1=83=D1=81=D1=82=D0=B8 =D0=B8 =D0=B7=D0=B0=D0=B1=D1=83= =D0=B4=D1=8C, I am one with the wind and sky Uppi =C3=AD himni eins og vindabl=C3=A6r =D0=AD=D1=82=D0=BE=D1=82 =D0=BC=D0=B8=D1=80 =D0=B8=D0=B7 =D1=82=D0=B2=D0=BE= =D0=B8=D1=85 =D0=B3=D1=80=D1=91=D0=B7. Let it go, let it go! =C3=9Eetta er n=C3=B3g, komi=C3=B0 n=C3=B3g =D0=9E=D1=82=D0=BF=D1=83=D1=81=D1=82=D0=B8 =D0=B8 =D0=B7=D0=B0=D0=B1=D1=83= =D0=B4=D1=8C, You'll never see me cry! Og t=C3=A1r m=C3=ADn enginn s=C3=A9r f=C3=A6r =D0=98 =D0=BD=D0=B5 =D0=B1=D1=83=D0=B4=D0=B5=D1=82 =D0=B1=D0=BE=D0=BB=D1=8C= =D1=88=D0=B5 =D1=81=D0=BB=D1=91=D0=B7. In fact, it's trivially easy to write something like this, because all this text is Unicode. ALL of these languages (and plenty more) are "well-covered by Unicode". There's still the ongoing debate of Han unification, plus the progressive work of adding characters for ancient scripts and such, but AFAIK, all writing systems currently in use are covered. ChrisA