Py-dea: Streamline string literals now!

Rick Johnson rantingrickjohnson at gmail.com
Wed Dec 28 14:36:17 EST 2011


On Dec 28, 12:58 am, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> On Tue, 27 Dec 2011 21:34:19 -0800, Rick Johnson wrote:

> > I am also thinking that ANY quote char is a bad choice for string
> > literal delimiters. Why? Well because it is often necessary to embed
> > single or double quotes into a string literal. We need to use a
> > delimiter that is not a current delimiter elsewhere in Python, and also,
> > is a very rare char. I believe Mr Ewing found that perfect char in his
> > "Multi-line uber raw string literals!" (Just scroll down a bit at this
> > link)...
>
> >    http://www.cosc.canterbury.ac.nz/greg.ewing/python/ideas.html
>
> Not surprisingly, you haven't thought this through. I'm sure Greg Ewing
> has, which is why he hasn't proposed *replacing* string delimiters with
> his multi-line format. That's why he proposed it as a *statement* and not
> string-builder syntax.
>
> Without an end-delimiter, how do you embed string literals in expressions?

Did you even read what i wrote? And if you did, you missed the point!

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!



More information about the Python-list mailing list