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

Ron Adam ron3200 at gmail.com
Thu May 16 20:51:13 CEST 2013



On 05/16/2013 12:38 PM, MRAB wrote:
>> I like the \ idea because it's clearly syntax and not an operator, but
>> the fact that it doesn't work with comments is annoying since one reason
>> to break a string is to insert comments. I don't like that spaces after
>> the \ are not allowed because trailing spaces are invisible to me but
>> not to the parser. So what if the rule for trailing \ was changed to:
>>
>>     The \ continuation character may be followed by white space and a
>>     comment. If a comment is present, there must be at least one
>>     whitespace character between the \ and the comment.
>>
>>
> Why do you say """there must be at least one whitespace character
> between the \ and the comment"""?


I'd like comments after a line continuation also.

There is an issue with it in strings.  The tokenizer uses the '\'+'\n' as a 
line continuation, rather than a single '\'.  By doing that, it can handle 
line continuations on any line exactly the same.

 >>> "This is a backslash \, and this\
...  line is continued also."
'This is a backslash \\, and this line is continued also.'

The \ is also used as a string escape sequence character also.


Outside of strings the '\' anywhere except at the end of a line is an 
error.  So we can do that without any issues with previous code.  But we 
need to not change it's behaviour between quotes.

Cheers

Ron



More information about the Python-ideas mailing list