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


Groups > comp.lang.python > #42752

Re: In defence of 80-char lines

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <jason.swails@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '(at': 0.04; 'skip:\xa0 30': 0.05; 'expressions': 0.07; 'skip:\xa0 40': 0.07; 'string': 0.09; 'literal': 0.09; 'meaningful': 0.09; 'cc:addr:python-list': 0.11; 'cc:name:python list': 0.16; 'effect.': 0.16; 'readable': 0.16; 'roy': 0.16; 'too).': 0.16; 'wary': 0.16; '\xa0this': 0.16; 'files.': 0.16; 'prevent': 0.16; ':-)': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; "python's": 0.19; 'thu,': 0.19; 'solution.': 0.20; 'email addr:gmail.com&gt;': 0.22; 'rules': 0.22; 'cc:addr:python.org': 0.22; 'parse': 0.24; 'string,': 0.24; 'together.': 0.24; 'cc:2**0': 0.24; '&gt;': 0.26; 'header:In- Reply-To:1': 0.27; 'point': 0.28; 'am,': 0.29; '8bit%:3': 0.30; 'cool': 0.30; 'message-id:@mail.gmail.com': 0.30; '8bit%:2': 0.31; 'figure': 0.32; 'regular': 0.32; 'run': 0.32; 'tool': 0.35; 'but': 0.35; 'received:google.com': 0.35; "didn't": 0.36; 'being': 0.38; 'sometimes': 0.38; 'jason': 0.38; 'enough': 0.39; 'how': 0.40; 'up,': 0.60; 'break': 0.61; 'making': 0.63; 'skip:r 40': 0.68; 'smith': 0.68; 'skip:r 30': 0.69; 'article': 0.77; 'embrace': 0.84; 'noise': 0.84; '\xa0but,': 0.84; 'technique': 0.93; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=eLgyqHP+41Akax/MYZZ0sZdYeoH+2lNMQZtml1Q3v4k=; b=nvWkd4gCxcTAo/n8YkNgmm3X20qW7tmHCuHyTr8VA/rf8LgFIIIR770ucKqVF82NCv 8kZObI6G3jO4+5YTZSovmJzgo242sbrh6E1FZloeNU/SGeNEtxg9ffmAVVlh2vjaS8uL AxE8jHe1E1/zQUs8j9h+MMexm0gE30e2MFbzks7WLTrRIzrhGlIs/yftt/yUd1bWxIU8 M5lN2RC7JBO+1ejJY7O/8MDTj6QuKlZ25kcvGQbSQ0O/SDVtIOqsHBCUHkYBWRjNxsF6 2w6EzBGkOOMghS12lTOiugiij8VWMSD+226hHpKLuLjV8/1HYfeJj/PcPcVdZ1xs/O2k eHXg==
MIME-Version 1.0
X-Received by 10.50.114.37 with SMTP id jd5mr4031227igb.2.1365081817109; Thu, 04 Apr 2013 06:23:37 -0700 (PDT)
In-Reply-To <roy-D6F29A.08394604042013@news.panix.com>
References <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> <mailman.96.1365077619.3114.python-list@python.org> <roy-D6F29A.08394604042013@news.panix.com>
Date Thu, 4 Apr 2013 09:23:37 -0400
Subject Re: In defence of 80-char lines
From Jason Swails <jason.swails@gmail.com>
To Roy Smith <roy@panix.com>
Content-Type multipart/alternative; boundary=047d7b3a98acccc2c804d988e069
Cc python list <python-list@python.org>
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.98.1365081820.3114.python-list@python.org> (permalink)
Lines 79
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1365081820 news.xs4all.nl 6875 [2001:888:2000:d::a6]:34242
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:42752

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Thu, Apr 4, 2013 at 8:39 AM, Roy Smith <roy@panix.com> wrote:

> In article <mailman.96.1365077619.3114.python-list@python.org>,
>  Jason Swails <jason.swails@gmail.com> wrote:
>
> > The only time I regularly break my rule is for regular expressions (at
> some
> > point I may embrace re.X to allow me to break those up, too).
>
> re.X is a pretty cool tool for making huge regexes readable.  But, it
> turns out that python's auto-continuation and string literal
> concatenation rules are enough to let you get much the same effect.
> Here's a regex we use to parse haproxy log files. This would be utter
> line noise all run together. This way, it's almost readable :-)
>
> pattern = re.compile(r'haproxy\[(?P<pid>\d+)]: '
>                      r'(?P<client_ip>(\d{1,3}\.){3}\d{1,3}):'
>                      r'(?P<client_port>\d{1,5}) '
>

For some reason that never occurred to me.  I use this technique every
other time I want to break up a long string, but never for regexes...

Now I will.  I was wary of using re.X since I sometimes use meaningful
whitespace in my regexes, and I didn't want to have to figure out how to
prevent them from being ignored...  This is a much better solution.

Thanks,
Jason

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


Thread

In defence of 80-char lines Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-04 01:36 +0000
  Re: In defence of 80-char lines Andrew Berg <bahamutzero8825@gmail.com> - 2013-04-03 20:59 -0500
  Re: In defence of 80-char lines Mitya Sirenef <msirenef@lightbird.net> - 2013-04-03 22:40 -0400
  Re: In defence of 80-char lines llanitedave <llanitedave@veawb.coop> - 2013-04-03 21:32 -0700
    Re: In defence of 80-char lines Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-04 06:33 +0000
    Re: In defence of 80-char lines gregor <gregor@ediwo.com> - 2013-04-04 08:40 +0200
    Re: In defence of 80-char lines Peter Otten <__peter__@web.de> - 2013-04-04 08:43 +0200
    Re: In defence of 80-char lines Tim Chase <python.list@tim.thechases.com> - 2013-04-04 06:09 -0500
    Re: In defence of 80-char lines Roy Smith <roy@panix.com> - 2013-04-04 07:52 -0400
      Re: In defence of 80-char lines llanitedave <llanitedave@veawb.coop> - 2013-04-04 08:28 -0700
    Re: In defence of 80-char lines Jason Swails <jason.swails@gmail.com> - 2013-04-04 08:18 -0400
    Re: In defence of 80-char lines Joshua Landau <joshua.landau.ws@gmail.com> - 2013-04-04 18:18 +0100
    Re: In defence of 80-char lines Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-04-04 18:22 -0400
  Re: In defence of 80-char lines rusi <rustompmody@gmail.com> - 2013-04-03 21:56 -0700
  Re: In defence of 80-char lines Rui Maciel <rui.maciel@gmail.com> - 2013-04-04 08:15 +0100
  Re: In defence of 80-char lines Jason Swails <jason.swails@gmail.com> - 2013-04-04 08:13 -0400
    Re: In defence of 80-char lines Roy Smith <roy@panix.com> - 2013-04-04 08:39 -0400
      Re: In defence of 80-char lines Jason Swails <jason.swails@gmail.com> - 2013-04-04 09:23 -0400
      Re: In defence of 80-char lines Neil Cerutti <neilc@norwich.edu> - 2013-04-04 15:56 +0000
      Re: In defence of 80-char lines Kushal Kumaran <kushal.kumaran+python@gmail.com> - 2013-04-04 23:04 +0530
        Re: In defence of 80-char lines Roy Smith <roy@panix.com> - 2013-04-04 19:55 -0400
  Re: In defence of 80-char lines Mitya Sirenef <msirenef@lightbird.net> - 2013-04-04 12:12 -0400
  Re: In defence of 80-char lines jmfauth <wxjmfauth@gmail.com> - 2013-04-04 13:28 -0700
    Re: In defence of 80-char lines Jason Swails <jason.swails@gmail.com> - 2013-04-04 17:00 -0400
    Re: In defence of 80-char lines Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-05 00:14 +0000

csiph-web