Python allows a single string literal to cross multiple lines, provided it 
begins and ends with three quote characters, e.g.

    s = """this string continues
    on the next line."""

There is a drawback with this: any whitespace at the start of the continuation 
line is included as part of the string:

    >>> print(s)
    this string continues
        on the next line.

So really, you should write it more like

    s = """this string continues
on the next line."""

which gets a bit ugly.

Python has quite a different convention for its compound statements, which can 
(and usually do) continue across multiple lines: and that is the use of 
indentation to denote nesting.

So I propose adapting this convention to triply-quoted strings, as follows: 
lines where the string literal continues must begin with the *same* initial 
whitespace as the line where the string started. This initial whitespace is 
stripped off before including the rest as part of the string. Any additional 
whitespace after that at the start of the line becomes part of the string. So 
the first example would now print as

    >>> print(s)
    this string continues
    on the next line.

which looks more like what was intended.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to