Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36189

Re: Need a specific sort of string modification. Can someone help?

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
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; 'debug': 0.05; 'debugging': 0.05; 'say,': 0.05; 'socket': 0.05; 'lines.': 0.07; 'parser': 0.07; 'rewrite': 0.07; 'subject:help': 0.07; 'expectation': 0.09; 'machines.': 0.09; 'received:mail-vc0-f174.google.com': 0.09; 'splitting': 0.09; 'subject:skip:m 10': 0.09; 'subject:string': 0.09; 'language': 0.14; '"good': 0.16; 'anyway).': 0.16; 'frames.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'least,': 0.16; 'meanwhile,': 0.16; 'measured': 0.16; 'petabytes': 0.16; 'pythonic': 0.16; 'rewrites': 0.16; 'rewriting': 0.16; 'roy': 0.16; 'splits': 0.16; 'sure.': 0.16; 'string': 0.17; 'wrote:': 0.17; 'bytes': 0.17; 'jan': 0.18; 'code,': 0.18; 'changes': 0.20; 'written': 0.20; 'trying': 0.21; 'fairly': 0.21; 'explicit': 0.22; 'ones.': 0.22; 'parse': 0.22; 'work,': 0.22; "i'd": 0.22; 'machine': 0.24; 'header:In-Reply- To:1': 0.25; 'am,': 0.27; 'bugs': 0.27; 'c++': 0.27; 'found.': 0.27; 'important.': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'fixed': 0.28; 'went': 0.28; 'chris': 0.28; 'run': 0.28; '(since': 0.29; 'ansi': 0.29; 'bad.': 0.29; 'complete,': 0.29; 'factor': 0.29; 'piece': 0.29; 'received:209.85.220.174': 0.29; 'though.': 0.29; 'character': 0.29; 'probably': 0.29; 'code': 0.31; '(and': 0.32; 'point,': 0.33; 'to:addr:python-list': 0.33; 'that,': 0.34; 'version': 0.34; "can't": 0.34; 'received:google.com': 0.34; 'clear': 0.35; 'data,': 0.35; 'faster': 0.35; 'machines': 0.35; 'sequence': 0.35; 'especially': 0.35; 'received:209.85.220': 0.35; 'subject:?': 0.35; 'similar': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.36; 'client': 0.36; 'test': 0.36; 'too': 0.36; 'problems': 0.36; 'unable': 0.36; 'level': 0.37; 'uses': 0.37; 'being': 0.37; 'ones': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'brief': 0.38; 'easier': 0.38; 'things': 0.38; 'performance': 0.39; 'to:addr:python.org': 0.39; 'easily': 0.39; 'called': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'most': 0.61; 'high': 0.61; 'map': 0.61; 'subject:Need': 0.61; 'helps': 0.63; 'different': 0.63; 'ever': 0.63; 'more': 0.63; 'within': 0.64; 'become': 0.65; 'subject:. ': 0.66; 'finally': 0.66; 'analysis': 0.70; 'obvious': 0.71; 'smith': 0.71; 'miss': 0.75; 'article': 0.78; 'discovered': 0.83; '2013': 0.84; 'clearer': 0.84; 'divide': 0.84; 'embarked': 0.84; 'skill.': 0.84; 'instantly': 0.93; 'demand': 0.96
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=sVmwR831Kbr2TZKeaZyX2kDWOKjZfe8wXSEmKMgvErA=; b=J8cs8gOJEwCDFXJbuu0nGpwDIbtsT0yDdCMLGAdterdVcdw6fPxfTRZZOC3/AouqhD 083QljckeZqWrEJh4J0FsDSCauY8Fxf9Lnjy5UnYjDUUrJANGgwVS5sCV17wFsMRptwu VbGzxGQu2DPPr418lmnPBs61gcloEOD2nulHjDn0c/atktAriQ+ltGG9/mEJv9IA5LpT PfUJvkpIyCDUoO2ZIExUMW8QEaX1VojvQmkVD4FTq3qV91Ilm0O6JwprcW1+IsGY9qE7 Efhb1pCQtOUAtkurLKZxKGk8LmbAjLM0FgJtXShvq7QPq53kZPHwl3WPsAi5Mka1wxjm 3ANQ==
MIME-Version 1.0
In-Reply-To <roy-088CDF.10385405012013@news.panix.com>
References <e480480d-f3b4-4491-969c-7d1843bf9e33@googlegroups.com> <mailman.109.1357378077.2939.python-list@python.org> <roy-564DD8.09304505012013@news.panix.com> <mailman.120.1357397255.2939.python-list@python.org> <roy-00F3AB.10030605012013@news.panix.com> <mailman.121.1357398573.2939.python-list@python.org> <roy-088CDF.10385405012013@news.panix.com>
Date Sun, 6 Jan 2013 02:57:29 +1100
Subject Re: Need a specific sort of string modification. Can someone help?
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.127.1357401452.2939.python-list@python.org> (permalink)
Lines 54
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1357401452 news.xs4all.nl 6914 [2001:888:2000:d::a6]:47126
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:36189

Show key headers only | View raw


On Sun, Jan 6, 2013 at 2:38 AM, Roy Smith <roy@panix.com> wrote:
> In article <mailman.121.1357398573.2939.python-list@python.org>,
>  Chris Angelico <rosuav@gmail.com> wrote:
>
>> it may or may not run faster than the explicit state machine,
>
> You got me by a factor of 3 or 4.  Not bad.

You miss my point, though. I went for simple Pythonic code, and never
measured its performance, on the expectation that it's "good enough".
Written in C, the state machine is probably WAY faster than splitting
and then iterating. My C++ MUD client uses code similar to that to
parse TELNET and ANSI codes from a stream of bytes in a socket (and
one of its "states" is that there's no more data available, so wait on
the socket); the rewrite in a high level language divides the string
on "\xFF" for TELNET and "\x1B" for ANSI, working them separately, and
then afterward splits on "\n" to divide into lines. The code's much
less convoluted, it's easier to test different parts (because I can
simply call the ANSI parser with a block of text), and on a modern
computer, you can't see the performance difference (since you spend
most of your time waiting for socket data anyway).

But it's gratifying to know that the obvious and brief way to do
things is fast too :)

>> but IMHO it's a lot clearer to read a split() than something
>> that changes state when a particular character is found.
>
> Maybe.  But being familiar with state machines is still a handy skill.
> DNA sequence analysis has lots of problems like "find a start codon
> which is within about 50 bases of a binding site, and then copy
> everything up until you find a stop codon".  Things like that often map
> well to state machines.  Especially if you're trying to do it in
> parallel in all three reading frames.

Sure. And if you're working with petabytes of data, these
considerations become fairly important. When that happens, you start
rewriting your algorithms in C, or using Cython, or something; at very
least, you start rewriting clear and simple algorithms into more
complex ones. But all this happens *after* the code has been tested
and proven. All the rewrites can be verified as being identical to
their reference implementations; you can test one piece at a time as
you change them. It's ever so much easier to work that way.

<anecdote>At work, we had one employee whose code was, shall we say,
less than stellar. At one point, he embarked on a months-long rewrite
of one of his modules; meanwhile, I was unable to adequately test code
that called on it. Once the rewrite was finally complete, I discovered
myriad bugs in my own code, ones that would have been found and fixed
instantly if I'd had even a slow version of the code to work against.
Starting with something you can easily debug helps enormously with
that, because debugging doesn't demand mega-TPS throughput.</anecdote>

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Need a specific sort of string modification. Can someone help? Sia <hossein.asgharian@gmail.com> - 2013-01-05 00:35 -0800
  Re: Need a specific sort of string modification. Can someone help? Frank Millman <frank@chagford.com> - 2013-01-05 11:15 +0200
  Re: Need a specific sort of string modification. Can someone help? Chris Angelico <rosuav@gmail.com> - 2013-01-05 20:27 +1100
    Re: Need a specific sort of string modification. Can someone help? Roy Smith <roy@panix.com> - 2013-01-05 09:30 -0500
      Re: Need a specific sort of string modification. Can someone help? Chris Angelico <rosuav@gmail.com> - 2013-01-06 01:47 +1100
        Re: Need a specific sort of string modification. Can someone help? Roy Smith <roy@panix.com> - 2013-01-05 10:03 -0500
          Re: Need a specific sort of string modification. Can someone help? Chris Angelico <rosuav@gmail.com> - 2013-01-06 02:09 +1100
            Re: Need a specific sort of string modification. Can someone help? Roy Smith <roy@panix.com> - 2013-01-05 10:38 -0500
              Re: Need a specific sort of string modification. Can someone help? Chris Angelico <rosuav@gmail.com> - 2013-01-06 02:57 +1100
              Re: Need a specific sort of string modification. Can someone help? Ian Kelly <ian.g.kelly@gmail.com> - 2013-01-05 13:04 -0700
              Re: Need a specific sort of string modification. Can someone help? Chris Angelico <rosuav@gmail.com> - 2013-01-06 07:32 +1100
                Re: Need a specific sort of string modification. Can someone help? Roy Smith <roy@panix.com> - 2013-01-05 15:47 -0500
                Re: Need a specific sort of string modification. Can someone help? Roy Smith <roy@panix.com> - 2013-01-06 12:28 -0500
                Re: Need a specific sort of string modification. Can someone help? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-06 23:19 +0000
  Re: Need a specific sort of string modification. Can someone help? Roy Smith <roy@panix.com> - 2013-01-05 09:12 -0500
  Re: Need a specific sort of string modification. Can someone help? Tim Chase <python.list@tim.thechases.com> - 2013-01-05 11:24 -0600
  Re: Need a specific sort of string modification. Can someone help? Tim Chase <python.list@tim.thechases.com> - 2013-01-05 12:49 -0600
  Re: Need a specific sort of string modification. Can someone help? Mitya Sirenef <msirenef@lightbird.net> - 2013-01-06 01:32 -0500
  Re: Need a specific sort of string modification. Can someone help? Mitya Sirenef <msirenef@lightbird.net> - 2013-01-06 14:53 -0500
  Re: Need a specific sort of string modification. Can someone help? Nick Mellor <thebalancepro@gmail.com> - 2013-01-06 18:48 -0800
  Re: Need a specific sort of string modification. Can someone help? Nick Mellor <thebalancepro@gmail.com> - 2013-01-06 19:40 -0800
    Re: Need a specific sort of string modification. Can someone help? Nick Mellor <thebalancepro@gmail.com> - 2013-01-06 21:28 -0800
  Re: Need a specific sort of string modification. Can someone help? Nick Mellor <thebalancepro@gmail.com> - 2013-01-06 21:30 -0800
  Re: Need a specific sort of string modification. Can someone help? John Ladasky <john_ladasky@sbcglobal.net> - 2013-01-06 21:39 -0800
  Re: Need a specific sort of string modification. Can someone help? Nick Mellor <thebalancepro@gmail.com> - 2013-01-06 23:07 -0800

csiph-web