[Python-ideas] multiline string notation
ncoghlan at gmail.com
Tue Sep 28 12:49:04 CEST 2010
These two questions are ones where good arguments can be made in both
Having explicit notation for multi-line strings is primarily a benefit
for readability and error detection. The readability benefit is that
it flags to the reader that the next string literal may cover several
lines. As Mike noted, the error detection benefit is that the parser
can more readily detect a missing end-quote from a normal string
instead of inadvertently treating the entire rest of the file as part
of the string and giving a relatively useless error regarding EOF
while parsing a string.
Stripping leading whitespace even inside strings is potentially
convenient for the programmer, but breaks the tokenisation stream.
String literals are meant to be atomic. Having the parser digging
inside them to declare certain whitespace to not be part of the string
despite its presence in the source code is certainly a valid design
choice a language could make when defining its grammar, but would
actually be a fairly significant change for Python.
For Python, these two rules are a case of "status quo wins a
stalemate". Changing Python's behaviour in this area would be
difficult and time-consuming for negligible benefit, so it really
isn't worth doing.
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas