Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #42752
| References | <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> <mailman.96.1365077619.3114.python-list@python.org> <roy-D6F29A.08394604042013@news.panix.com> |
|---|---|
| Date | 2013-04-04 09:23 -0400 |
| Subject | Re: In defence of 80-char lines |
| From | Jason Swails <jason.swails@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.98.1365081820.3114.python-list@python.org> (permalink) |
[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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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