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

Terry Reedy tjreedy at udel.edu
Fri Nov 5 21:37:47 CET 2010

On 11/5/2010 10:45 AM, Nick Coghlan wrote:

> I do use the textwrap.dedent workaround myself, but I think it is
> sufficiently flawed for a proper fix to be worth considering:
> 1. It doesn't work for docstrings (as Tal pointed out)

This does:

def f(x):
     "Am I a docstring\n"\
     "even though I start in pieces?\n"\
     "Oh, x is a dummy param\n"

# prints 3 lines, but not without '\' escape at line ends

> 2. It postpones until runtime an operation that could fairly easily be
> carried out at compile time instead

Above is. Not that I like the extra fluff needed to make it work.
It makes a 'd' for dedent literal prefix look inviting.

Terry Jan Reedy

More information about the Python-ideas mailing list