[Python-ideas] Implicit string literal concatenation considered harmful?

Vernon D. Cole vernondcole at gmail.com
Fri May 17 11:37:17 CEST 2013


on Fri, 17 May 2013 18:49:14 +1000 Steven D'Aprano wrote:

>
> Concatenating strings on the same line is a legitimate thing to do,
> because you can mix different quoting types. In my opinion, there's no
> really clean way to build string literals containing multiple types of
> quotation marks, but implicit concatenation works and is useful. Here's a
> contrived example:
>
>
> s = "'Aren't you supposed to be " '"working"?' "', he asked with a wink."
>
> True.  But I had to paste your example into the interpreter to figure out
where the literals ended and started.

s = "'Aren't you supposed to be " ... '"working"?' ... "', he asked with a
wink."

Is easier to read and understand. So is:

s = "'Aren't you supposed to be " + '"working"?' + "', he asked with a
wink."

Which works today, if you don't mind doing it at run time. You can also use:

s = """'Aren't you supposed to be "working"? ', he asked with a wink."""

Which also works fine, although the triple-double single-single combination
is a bit frightening to look at.
--
Vernon Cole
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130517/68bec2f8/attachment.html>


More information about the Python-ideas mailing list