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


Groups > comp.lang.python > #18141

Re: Py-dea: Streamline string literals now!

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.023
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'scripting': 0.05; 'char': 0.07; 'python': 0.08; 'readable': 0.09; 'subject:string': 0.09; '"embedded': 0.16; 'awk': 0.16; 'char,': 0.16; 'delimited': 0.16; 'delimiters': 0.16; 'see.': 0.16; 'shell=true)': 0.16; '{0}': 0.16; 'this:': 0.16; 'wed,': 0.17; 'wrote:': 0.18; 'dec': 0.22; 'header:In-Reply-To:1': 0.22; 'string': 0.24; 'received:74.125.82.174': 0.24; 'besides': 0.24; 'shell': 0.24; 'all,': 0.28; 'message-id:@mail.gmail.com': 0.28; 'source,': 0.29; 'pm,': 0.29; 'idea': 0.32; 'people,': 0.32; 'sort': 0.33; 'to:addr :python-list': 0.34; 'anything': 0.34; 'received:74.125.82': 0.35; 'especially': 0.35; 'however,': 0.36; 'like,': 0.37; 'received:74.125': 0.37; 'received:google.com': 0.37; 'think': 0.37; 'could': 0.37; 'using': 0.38; 'replace': 0.38; 'easier': 0.38; 'should': 0.39; 'being': 0.39; 'johnson': 0.39; 'to:addr:python.org': 0.40; 'might': 0.40; 'more': 0.61; '2011': 0.61; 'your': 0.61; 'stop': 0.63; 'choice.': 0.64; 'perfect': 0.64; 'subject:!': 0.67; 'multi': 0.67; 'escaping': 0.84; 'nice,': 0.84; 'was...': 0.84; '-->': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=GSH9YrIjIj1Gpx+Xr7UYWQnK/XCXP6N3HlxyXjeYhYc=; b=Eb/60gbxSV27PiEjqTAuqykRSquGivYTVvMgxYGnUiI4bmOEWaQwRdPvyR965DVsLz IX5Yr8BpR8pYB89c0DXyg5eINvEp9yvJpmJpbEFKhkoSgfuCi5qe3qKcypO9G32e536V aVgEGY2Y1YeYMIXeHuv6Z72mFOdLuJIywmJM0=
MIME-Version 1.0
In-Reply-To <c233420e-81e8-49be-baa2-12f71f5fc09e@n39g2000yqh.googlegroups.com>
References <280841b8-8674-4c1d-9a82-28982340a4b8@v24g2000yqk.googlegroups.com> <b2ced8f0-81af-44be-9cea-b6257c84d284@p13g2000yqd.googlegroups.com> <4efabe1d$0$29966$c3e8da3$5496439d@news.astraweb.com> <c233420e-81e8-49be-baa2-12f71f5fc09e@n39g2000yqh.googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 28 Dec 2011 13:52:31 -0700
Subject Re: Py-dea: Streamline string literals now!
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.4195.1325105584.27778.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1325105584 news.xs4all.nl 6950 [2001:888:2000:d::a6]:56767
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:18141

Show key headers only | View raw


On Wed, Dec 28, 2011 at 12:36 PM, Rick Johnson
<rantingrickjohnson@gmail.com> wrote:
> My point was... while Greg's idea is nice, it is not the answer.
> HOWEVER, he did find the perfect char, and that char is the pipe! -->
> |
>
> mlstr = |||
> this is a
> multi line sting that is
> delimited by "triple pipes". Or we
> could just 'single pipes' if we like, however, i think
> the "triple pipe' is easier to see. Since the pipe char
> is so rare in Python source, it becomes the obvious
> choice. And, best of all, no more worries about
> "embedded quotes". YAY!
> |||
>
> slstr = |this is a single line string|
>
> The point is people, we should be using string delimiters that are
> ANYTHING besides " and '. Stop being a sheep and use your brain!

So those who do shell scripting from Python might replace this:

subprocess.call("cat {0} | awk '/foo|bar/ {print $3;}' | sort | uniq
>{1}".format(infile, outfile), shell=True)

with this:

subprocess.call(|cat {0} \| awk '/foo\|bar/ {print $3;}' \| sort \|
uniq >{1}|.format(infile, outfile), shell=True)

or if we combine Rick's string escaping proposal:

subprocess.call(|cat {0} <PIPE> awk '/foo<PIPE>bar/ {print $3;}'
<PIPE> sort <PIPE> uniq <GT>{1}|.format(infile, outfile), shell=True)

Yeah, that's so much better.  I especially like how nice and readable
the regex is now.

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


Thread

Py-dea: Streamline string literals now! Rick Johnson <rantingrickjohnson@gmail.com> - 2011-12-27 19:49 -0800
  Re: Py-dea: Streamline string literals now! Chris Angelico <rosuav@gmail.com> - 2011-12-28 15:17 +1100
    Re: Py-dea: Streamline string literals now! Rick Johnson <rantingrickjohnson@gmail.com> - 2011-12-27 20:36 -0800
  Re: Py-dea: Streamline string literals now! Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-28 04:20 +0000
  Re: Py-dea: Streamline string literals now! Rick Johnson <rantingrickjohnson@gmail.com> - 2011-12-27 21:34 -0800
    Re: Py-dea: Streamline string literals now! Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-28 06:58 +0000
      Re: Py-dea: Streamline string literals now! Rick Johnson <rantingrickjohnson@gmail.com> - 2011-12-28 11:36 -0800
        Re: Py-dea: Streamline string literals now! Dominic Binks <dbinks@codeaurora.org> - 2011-12-28 12:10 -0800
        Re: Py-dea: Streamline string literals now! Lie Ryan <lie.1296@gmail.com> - 2011-12-29 07:13 +1100
        Re: Py-dea: Streamline string literals now! Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-28 13:52 -0700
        Re: Py-dea: Streamline string literals now! Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-28 22:54 +0000
          Re: Py-dea: Streamline string literals now! Chris Angelico <rosuav@gmail.com> - 2011-12-29 10:08 +1100
          Re: Py-dea: Streamline string literals now! Dan Sommers <dan@tombstonezero.net> - 2011-12-29 01:44 +0000
          Re: Py-dea: Streamline string literals now! Lie Ryan <lie.1296@gmail.com> - 2011-12-30 10:19 +1100
          Re: Py-dea: Streamline string literals now! Chris Angelico <rosuav@gmail.com> - 2011-12-30 10:24 +1100
    Re: Py-dea: Streamline string literals now! Chris Angelico <rosuav@gmail.com> - 2011-12-28 18:47 +1100
    Re: Py-dea: Streamline string literals now! Lie Ryan <lie.1296@gmail.com> - 2011-12-29 07:53 +1100
    Re: Py-dea: Streamline string literals now! python@bdurham.com - 2011-12-28 16:03 -0500
    Re: Py-dea: Streamline string literals now! Nathan Rice <nathan.alexander.rice@gmail.com> - 2011-12-28 16:24 -0500
    Re: Py-dea: Streamline string literals now! Chris Angelico <rosuav@gmail.com> - 2011-12-29 08:42 +1100
    Re: Py-dea: Streamline string literals now! Nathan Rice <nathan.alexander.rice@gmail.com> - 2011-12-28 17:24 -0500
    Re: Py-dea: Streamline string literals now! Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-12-29 00:00 -0500

csiph-web