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: 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: References: <280841b8-8674-4c1d-9a82-28982340a4b8@v24g2000yqk.googlegroups.com> <4efabe1d$0$29966$c3e8da3$5496439d@news.astraweb.com> From: Ian Kelly 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Wed, Dec 28, 2011 at 12:36 PM, Rick Johnson 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} awk '/foobar/ {print $3;}' sort uniq {1}|.format(infile, outfile), shell=True) Yeah, that's so much better. I especially like how nice and readable the regex is now.