[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Indented multi-line strings (was: "Data blocks" syntax specification draft)

On Wed, May 23, 2018 at 10:25 AM, Peter J. Holzer <hjp-python at hjp.at> wrote:
> How about this?
>     x = ''''
>         Here is a multi-line string
>             with
>           indentation.
>         ''''
> This would be equivalent to
>     x = 'Here is a multi-line string\n    with\n  indentation.'
> Rules:
>  * The leading and trailing '''' must be aligned vertically.

Ick, why? What's wrong with letting the trailing delimiter be at the
end of a line, or the beginning with no indentation?

>  * The contents of the string must be indented at least as far as the
>    delimiters (and with consistent tabs/spaces).
>    This leading white space is ignored.
>  * All the leading white space beyond this 'left edge' is preserved.
>  * The newlines after the leading '''' and before the trailing '''' are
>    ignored, all the others preserved. (I thought about preserving the
>    trailing newline, but it is easier to add one than remove one.)

How about we instead just use the rules from PEP 257 so that there
aren't two different sets of multi-line string indentation rules to
have to remember?


Also, how about using a string prefix character instead of making
quad-quote meaningful? Apart from being hard to visually distinguish
from triple-quote, this would break existing triple-quote strings that
happen to start with the quote character, e.g ''''What?' she asked.'''

I don't know if 'i' would be the right prefix character for this, but
it's unused and is short for 'indented':

b = i'''
    Here is a multi-line string
    with indentation, which is
    determined from the second