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


Groups > comp.lang.python > #38304

Re: Curious to see alternate approach on a search/replace via regex

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <demianbrecht@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.047
X-Spam-Evidence '*H*': 0.91; '*S*': 0.00; 'be:': 0.09; 'method:': 0.09; 'url:github': 0.09; "'_')": 0.16; 'subject:search': 0.16; 'wrote:': 0.17; 'import': 0.21; "i'd": 0.22; 'to:2**1': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'subject:/': 0.28; 'skip:( 20': 0.28; "skip:' 10": 0.30; 'function': 0.30; 'seconds': 0.30; 'print': 0.32; 'to:addr:python- list': 0.33; 'received:google.com': 0.34; 'compared': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'message-id:@gmail.com': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'skip:p 20': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'received:10': 0.38; 'to:addr:python.org': 0.39; 'skip:a 40': 0.61; 'of:': 0.65; 'url:a': 0.72; 'subject:via': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:user-agent:date:subject:from:to:message-id:thread-topic :in-reply-to:mime-version:content-type:content-transfer-encoding; bh=/DrZhuPiE1u0j2kjh9WAcaJtnOoDhUa0TXu5IsOKZ/0=; b=b0cs8nJmEKyjNTZZizc80pEfvwCyVNk6FzDnOPDZ4y0FkilevS2kXh66JMtHFs7m4D mrWWCc7+bHtOvN5r/bgxitKBrDKZuRNGKyPhbJSZu9coPTWuC09EmI3Q7YefzMo1mNzA Caukn/iSs48T0TgXIADo40BZmn1UunvCQHoHFYUBuSvNicwXjP8twvwKd/+oIseMkI/n IvvKZwsBB2zGk6gN53XjcUugZTxGzcrNXev/sH4fqTp1lNAFWDIC9BrR371fyFLxkExo WUZJzeUm2uleZP7l41ubJNV2tVLH+6vRL7usXoCcmJaWTIEJxSAD1ztmvZ27DdTzdRBu bK9w==
X-Received by 10.66.82.35 with SMTP id f3mr78325795pay.49.1360187765850; Wed, 06 Feb 2013 13:56:05 -0800 (PST)
User-Agent Microsoft-MacOutlook/14.3.0.121105
Date Wed, 06 Feb 2013 13:55:58 -0800
Subject Re: Curious to see alternate approach on a search/replace via regex
From Demian Brecht <demianbrecht@gmail.com>
To rh <richard_hubbe11@lavabit.com>, <python-list@python.org>
Thread-Topic Curious to see alternate approach on a search/replace via regex
In-Reply-To <20130206134105.9352d665e1f8d0719021fcf9@lavabit.com>
Mime-version 1.0
Content-type text/plain; charset="US-ASCII"
Content-transfer-encoding 7bit
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.1426.1360187770.2939.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360187770 news.xs4all.nl 6851 [2001:888:2000:d::a6]:55796
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38304

Show key headers only | View raw


Well, an alternative /could/ be:

from urlparse import urlparse

parts = urlparse('http://alongnameofasite1234567.com/q?sports=run&a=1&b=1')
print '%s%s_%s' % (parts.netloc.replace('.', '_'),
    parts.path.replace('/', '_'),
    parts.query.replace('&', '_').replace('=', '_')
    ) 


Although with the result of:

alongnameofasite1234567_com_q_sports_run_a_1_b_1
         1288 function calls in 0.004 seconds


Compared to regex method:

498 function calls (480 primitive calls) in 0.000 seconds

I'd prefer the regex method myself.

Demian Brecht
http://demianbrecht.github.com




On 2013-02-06 1:41 PM, "rh" <richard_hubbe11@lavabit.com> wrote:

>http://alongnameofasite1234567.com/q?sports=run&a=1&b=1

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


Thread

Re: Curious to see alternate approach on a search/replace via regex Demian Brecht <demianbrecht@gmail.com> - 2013-02-06 13:55 -0800
  Re: Curious to see alternate approach on a search/replace via regex Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-07 03:04 +0000
    Re: Curious to see alternate approach on a search/replace via regex rh <richard_hubbe11@lavabit.com> - 2013-02-06 19:31 -0800
      Re: Curious to see alternate approach on a search/replace via regex Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-08 09:45 +1100
        Re: Curious to see alternate approach on a search/replace via regex rh <richard_hubbe11@lavabit.com> - 2013-02-07 15:13 -0800
          Re: Curious to see alternate approach on a search/replace via regex Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-08 10:59 +1100
            Re: Curious to see alternate approach on a search/replace via regex Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-07 17:55 -0700
              Re: Curious to see alternate approach on a search/replace via regex Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-08 14:02 +1100
                Re: Curious to see alternate approach on a search/replace via regex rh <richard_hubbe11@lavabit.com> - 2013-02-07 21:35 -0800
            Re: Curious to see alternate approach on a search/replace via regex Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-07 18:08 -0700
            Re: Curious to see alternate approach on a search/replace via regex rh <richard_hubbe11@lavabit.com> - 2013-02-07 21:57 -0800
            Re: Curious to see alternate approach on a search/replace via regex Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-08 01:21 -0700
              Re: Curious to see alternate approach on a search/replace via regex Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-08 22:43 +1100
                Re: Curious to see alternate approach on a search/replace via regex Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-08 09:26 -0700
            Re: Curious to see alternate approach on a search/replace via regex Serhiy Storchaka <storchaka@gmail.com> - 2013-02-15 22:58 +0200
            Re: Curious to see alternate approach on a search/replace via regex rh <richard_hubbe11@lavabit.com> - 2013-02-26 11:20 -0800
        Re: Curious to see alternate approach on a search/replace via regex Dave Angel <davea@davea.name> - 2013-02-08 01:27 -0500
    Re: Curious to see alternate approach on a search/replace via regex jmfauth <wxjmfauth@gmail.com> - 2013-02-07 03:08 -0800
      Re: Curious to see alternate approach on a search/replace via regex Chris Angelico <rosuav@gmail.com> - 2013-02-07 23:44 +1100

csiph-web