[Python-ideas] Multi-line strings that respect indentation

Stephen J. Turnbull stephen at xemacs.org
Sun Nov 7 09:58:16 CET 2010

Jared Grubb writes:

 > The easiest would be to do the equivalent of dedent and take the
 > longest common whitespace length. But, the purist in me would kinda
 > hope that if, for example, the code was indented to column 8 but
 > the text was all at column 12, that the resulting string would have
 > 4 leading spaces on each line.


You could probably come up with rules to get this right for the
parser, but how can it possibly guess exactly what any given user
means by

    def amethod (self):
            Mary had a little lamb
            little lamb
            little lamb
            The lamb may be a little small
            But this poem is just plain lame.""")

Is that supposed to be flush left, indented 4 spaces, indented 8
spaces, or indented 12 spaces?

I think the dedent rule (longest common whitespace prefix) makes the
most sense.

More information about the Python-ideas mailing list