Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.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; 'intermediate': 0.05; 'say,': 0.05; 'ascii': 0.07; 'bytes.': 0.07; 'objects,': 0.07; 'type,': 0.07; 'subject:How': 0.09; 'python': 0.09; 'encode': 0.09; 'immutable': 0.09; 'internally': 0.09; 'mode,': 0.09; 'patches': 0.09; 'pep': 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; 'thread,': 0.09; 'stored': 0.10; ';-)': 0.11; 'aug': 0.13; 'language': 0.14; 'encoding': 0.15; 'consciously': 0.16; 'earlier.': 0.16; 'pairs': 0.16; 'range.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'socket.': 0.16; 'subject: \n ': 0.16; 'subject:unicode': 0.16; 'subject:variable': 0.16; 'mon,': 0.16; 'string': 0.17; 'wrote:': 0.17; 'byte': 0.17; 'bytes': 0.17; 'copied': 0.17; 'string,': 0.17; 'unicode': 0.17; 'jan': 0.18; '(or': 0.18; 'bit': 0.21; 'earlier': 0.21; 'somewhere': 0.24; 'header': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'creating': 0.26; 'am,': 0.27; 'done.': 0.27; 'expansion': 0.27; 'first.': 0.27; 'see,': 0.27; 'correct': 0.28; 'fixed': 0.28; 'header:X-Complaints-To:1': 0.28; 'chris': 0.28; 'fine': 0.28; '(possibly': 0.29; 'declared': 0.29; 'obscure': 0.29; 'strings,': 0.29; 'maybe': 0.29; 'usually': 0.30; 'writes': 0.30; 'function': 0.30; 'file': 0.32; 'more,': 0.32; 'goes': 0.33; 'done,': 0.33; 'ones,': 0.33; 'safely': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; "can't": 0.34; 'text': 0.34; 'clear': 0.35; 'whatever': 0.35; 'open': 0.35; 'pm,': 0.35; 'something': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'characters': 0.36; "wasn't": 0.36; 'should': 0.36; 'possible': 0.37; 'optimization': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'sure': 0.38; 'several': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'end': 0.40; 'claim': 0.60; 'further': 0.61; 'different': 0.63; 'details': 0.63; 'making': 0.64; '20,': 0.65; 'content,': 0.65; 'obvious': 0.71; 'lays': 0.84; 'pike': 0.84; 'received:fios.verizon.net': 0.84; 'subject:value': 0.84 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 20:35:30 -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> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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: 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: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1345422959 news.xs4all.nl 6925 [2001:888:2000:d::a6]:39791 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27445 On 8/19/2012 6:42 PM, Chris Angelico wrote: > On Mon, Aug 20, 2012 at 3:34 AM, Terry Reedy wrote: >> Python has often copied or borrowed, with adjustments. This time it is the >> first. I should have added 'that I know of' ;-) > Maybe it wasn't consciously borrowed, but whatever innovation is done, > there's usually an obscure beardless language that did it earlier. :) > > Pike has a single string type, which can use the full Unicode range. > If all codepoints are <256, the string width is 8 (measured in bits); > if <65536, width is 16; otherwise 32. Using the inbuilt count_memory > function (similar to the Python function used somewhere earlier in > this thread, but which I can't at present put my finger to), I find > that for strings of 16 bytes or more, there's a fixed 20-byte header > plus the string content, stored in the correct number of bytes. (Pike > strings, like Python ones, are immutable and do not need expansion > room.) It is even possible that someone involved was even vaguely aware that there was an antecedent. The PEP makes no claim that I can see, but lays out the problem and goes right to details of a Python implementation. > However, Python goes a bit further by making it VERY clear that this > is a mere optimization, and that Unicode strings and bytes strings are > completely different beasts. In Pike, it's possible to forget to > encode something before (say) writing it to a socket. Everything works > fine while you have only ASCII characters in the string, and then > breaks when you have a >255 codepoint - or perhaps worse, when you > have a 127