On Wed, Dec 28, 2011 at 12:36 PM, Rick Johnson <rantingrickjohn...@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. -- http://mail.python.org/mailman/listinfo/python-list