Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed6.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'alias': 0.07; 'ascii': 0.07; 'bytes.': 0.07; 'character,': 0.07; 'utf-8': 0.07; 'python': 0.09; 'backwards': 0.09; 'comfortably': 0.09; 'expense': 0.09; 'indexes': 0.09; 'subject:string': 0.09; 'substring': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'aug': 0.13; 'index': 0.13; 'language': 0.14; '(the': 0.15; 'sat,': 0.15; '[*]': 0.16; 'bend': 0.16; 'correctly,': 0.16; 'int32': 0.16; 'reason).': 0.16; 'subject:unicode': 0.16; '\xc3\xa9crit\xc2\xa0:': 0.16; 'string': 0.17; 'wrote:': 0.17; 'bytes': 0.17; 'unicode': 0.17; 'memory': 0.18; 'discussion': 0.20; 'sorry,': 0.22; 'cc:2**0': 0.23; 'split': 0.23; 'this:': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'looks': 0.26; 'am,': 0.27; 'actual': 0.28; 'arrays': 0.29; 'strings,': 0.29; 'related': 0.30; 'code': 0.31; 'skip:s 30': 0.33; 'equal': 0.33; 'received:google.com': 0.34; 'sequence': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'except': 0.36; 'but': 0.36; 'characters': 0.36; 'beyond': 0.37; 'two': 0.37; 'quite': 0.37; 'received:209': 0.37; 'far': 0.37; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'some': 0.38; 'nothing': 0.38; 'instead': 0.39; 'your': 0.60; 'from:no real name:2**0': 0.60; 'subject:, ': 0.61; 'containing': 0.61; 'first': 0.61; 'perfect': 0.63; 'subject:...': 0.63; 'more': 0.63; '8bit%:38': 0.65; 'skill': 0.65; 'subject.': 0.65; 'middle': 0.66; 'sounds': 0.71; 'chinese': 0.78; 'composing': 0.84; 'reminds': 0.84; 'subject:, ...': 0.84; 'seriously,': 0.91; 'technically': 0.91 Newsgroups: comp.lang.python Date: Sat, 25 Aug 2012 23:59:34 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=83.78.186.59; posting-account=ung4FAoAAAC46zhHJ0Nsnuox7M5gDvs_ References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 83.78.186.59 MIME-Version: 1.0 Subject: Re: Flexible string representation, unicode, typography, ... From: wxjmfauth@gmail.com To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: Python 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: , Message-ID: Lines: 80 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1345964382 news.xs4all.nl 6951 [2001:888:2000:d::a6]:42241 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27907 Le dimanche 26 ao=C3=BBt 2012 00:26:56 UTC+2, Ian a =C3=A9crit=C2=A0: > On Sat, Aug 25, 2012 at 9:47 AM, wrote: >=20 > > For those you do not know, the go language has introduced >=20 > > the rune type. As far as I know, nobody is complaining, I >=20 > > have not even seen a discussion related to this subject. >=20 >=20 >=20 > Python has that also. We call it "int". >=20 >=20 >=20 > More seriously, strings in Go are not sequences of runes. They're >=20 > actually arrays of UTF-8 bytes. That means that they're quite >=20 > efficient for ASCII strings, at the expense of other characters, like >=20 > Chinese (wait, this sounds familiar for some reason). It also means >=20 > that you have to bend over backwards if you want to work with actual >=20 > runes instead of bytes. Want to know how many characters are in your >=20 > string? Don't call len() on it -- that will only tell you how many >=20 > bytes are in it. Don't try to index or slice it either -- that will >=20 > (accidentally) work for ASCII strings, but for other strings your >=20 > indexes will be wrong. If you're unlucky you might even split up the >=20 > string in the middle of a character, and now your string has invalid >=20 > characters in it. The right way to do it looks something like this: >=20 >=20 >=20 > len([]rune("=E7=99=BD=E9=B5=AC=E7=BF=94")) // get the length of the stri= ng in characters >=20 > string([]rune("=E7=99=BD=E9=B5=AC=E7=BF=94")[0:2]) // get the substring = containing the first >=20 > two characters >=20 >=20 >=20 > It reminds me of working in Python 2.X, except that instead of an >=20 > actual unicode type you just have arrays of ints. Sorry, you do not get it. The rune is an alias for int32. A sequence of runes is a sequence of int32's. Go do not spend its time in using a machinery to work with, to differentiate, to keep in memory this sequence according to the *characers* composing this "array of code points". The message is even stronger. Use runes to work comfortably [*] with unicode: rune -> int32 -> utf32 -> unicode (the perfect scheme, cann't be better) [*] Beyond my skill and my kwowloge and if I understood correctly, this rune is even technically optimized to ensure it it always an int32. len() or slices() have nothing to do here. My experience with go is equal to uero + epsilon. jmf