Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed5.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; 'languages,': 0.04; 'string.': 0.04; 'context': 0.05; 'escape': 0.07; 'indexing': 0.07; 'indices': 0.07; 'parsing': 0.07; 'subject:How': 0.09; 'python': 0.09; 'buffer,': 0.09; 'c/c++': 0.09; 'literal': 0.09; 'parsed': 0.09; 'subject:()': 0.09; 'subject:string': 0.09; 'subject:using': 0.09; 'aug': 0.13; 'encoding': 0.15; '(when': 0.16; 'ascii,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'happily': 0.16; 'jumping': 0.16; 'operation,': 0.16; 'pointers,': 0.16; 'subject:unicode': 0.16; 'subject:variable': 0.16; 'unicode.': 0.16; 'string': 0.17; 'wrote:': 0.17; 'cheap': 0.17; 'instance,': 0.17; 'skip': 0.17; 'string,': 0.17; 'unicode': 0.17; 'trying': 0.21; 'fairly': 0.21; 'received:209.85.214.174': 0.21; "i'd": 0.22; 'example': 0.23; "i've": 0.23; 'random': 0.24; 'paul': 0.24; 'header:In-Reply- To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'chris': 0.28; '(unless': 0.29; 'writes:': 0.29; 'character': 0.29; "i'm": 0.29; 'that.': 0.30; 'file': 0.32; 'retain': 0.33; 'to:addr:python- list': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'next': 0.35; 'but': 0.36; 'characters': 0.36; "i'll": 0.36; 'too': 0.36; 'being': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'easily': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'your': 0.60; "you'll": 0.62; '(that': 0.62; 'different': 0.63; 'information': 0.63; 'adobe': 0.65; 'fat': 0.84; 'forward.': 0.84; 'subject:value': 0.84 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:to :content-type; bh=dCycGA7cCtew/LSO4Lr8FHB8nEERSSXMJ7cWYB4fOjI=; b=gxZ3i2QtNfDNotJysYQXRhN4PliKnFHDTThGTOMQNEq/FpN27JiGOiQbibDklXjR56 2ugF+6QH05dbte9ELU7Oz22XYyj2j8xVIWYGgkH2fySgeioPj/1oE4mKq97jUOnCJW1F k179si+NnccnOhyWufOUoEgqtI2ATlOocuibxV/CkL+4rIlrd6Pjcin6NzhC3tgtn5WG 5kfjomjBnn2k7EfjHvTWqN2M8SB+4T3opiJIq+9xxtcvSTn0uT+skG1B/1H7mJ1GIxLq ObFIBFwD4O3ObRzUMGhzWFcsiyksKQllsZDt0vxTW4KjH29oCGTXC5FEJkLVjVv+uslZ 2y2w== MIME-Version: 1.0 In-Reply-To: <7x7gsv4lw4.fsf@ruckus.brouhaha.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <7xfw7j3a1x.fsf@ruckus.brouhaha.com> <7xtxvzehhb.fsf@ruckus.brouhaha.com> <7x7gsv4lw4.fsf@ruckus.brouhaha.com> Date: Sun, 19 Aug 2012 13:31:21 +1000 Subject: Re: How do I display unicode value stored in a string variable using ord() From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1345347084 news.xs4all.nl 6939 [2001:888:2000:d::a6]:58692 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27345 On Sun, Aug 19, 2012 at 1:10 PM, Paul Rubin wrote: > Chris Angelico writes: >> I don't have a Python example of parsing a huge string, but I've done >> it in other languages, and when I can depend on indexing being a cheap >> operation, I'll happily do exactly that. > > I'd be interested to know what the context was, where you parsed > a big unicode string in a way that required random access to > the nth character in the string. It's something I've done in C/C++ fairly often. Take one big fat buffer, slice it and dice it as you get the information you want out of it. I'll retain and/or calculate indices (when I'm not using pointers, but that's a different kettle of fish). Generally, I'm working with pure ASCII, but port those same algorithms to Python and you'll easily be able to read in a file in some known encoding and manipulate it as Unicode. It's not so much 'random access to the nth character' as an efficient way of jumping forward. For instance, if I know that the next thing is a literal string of n characters (that I don't care about), I want to skip over that and keep parsing. The Adobe Message Format is particularly noteworthy in this, but it's a stupid format and I don't recommend people spend too much time reading up on it (unless you like that sensation of your brain trying to escape through your ear). ChrisA