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: 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>': 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; '>': 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: References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Date: Thu, 4 Apr 2013 09:23:37 -0400 Subject: Re: In defence of 80-char lines From: Jason Swails To: Roy Smith Content-Type: multipart/alternative; boundary=047d7b3a98acccc2c804d988e069 Cc: python list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 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 --047d7b3a98acccc2c804d988e069 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Apr 4, 2013 at 8:39 AM, Roy Smith wrote: > In article , > Jason Swails 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\d+)]: ' > r'(?P(\d{1,3}\.){3}\d{1,3}):' > r'(?P\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 --047d7b3a98acccc2c804d988e069 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

<= /div>
On Thu, Apr 4, 2= 013 at 8:39 AM, Roy Smith <roy@panix.com> wrote:
In article <mailman.96.1365077619.3114.python-l= ist@python.org>,
=A0Jason 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. =A0But, = 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 =3D re.compile(r'haproxy\[(?P<pid>\d+)]: '
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0r'(?P<client_ip>(\d{1,= 3}\.){3}\d{1,3}):'
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0r'(?P<client_port>\d{1= ,5}) '

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

Now I will. =A0I 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 igno= red... =A0This is a much better solution.

Thanks,
Jason
--047d7b3a98acccc2c804d988e069--