Re: [Python-ideas] Implicit string literal concatenation considered harmful?
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
participants (1)
-
Vernon D. Cole