Automatic reformatting of triple-quoted strings (was Re: Few things)
Nick Coghlan
ncoghlan at email.com
Sat Nov 27 07:54:32 EST 2004
Carlos Ribeiro wrote:
> The idea is as follows:
>
> 1) triple-quote strings will automatically be reformatted to remove
> any extra space on the left side due to indentation. The indentation
> will be controled by the position of the leftmost non-space character
> in the string.
>
> 2) raw triple-quoted strings will *NOT* be reformatted. Any space to
> the left side is deemed to be significant.
>
> This is indeed a quite simple idea, with the potential to simplify
> some code. It will also encourage people to write triple-quoted
> strings for long strings, which is something that people usually do to
> avoid the extra space.
I'd be +0, since the behaviour you suggest is what I generally want when I use
long strings. However, I almost always set up such strings as module globals, so
the indenting issue doesn't usually bother me in practice. . .
If the compatibility problems prove to be a deal breaker (i.e. someone somewhere
actually wants the extra space, and adding an 'r' character to the source for
compatibility with a new Python release is too much of a burden), then another
alternative is a new string type character (e.g. 't' for 'trimmed', to use the
PEP 257 terminology. 'i' for 'indented' would also work - the source code for
the string literal is indented, so that indenting should be removed from the
resulting string).
The argument against the inevitable suggestion of just using a function (as you
already do) is that a function call doesn't work for a docstring.
Cheers,
Nick.
More information about the Python-list
mailing list