Thanks for all of your replies. I did not know about the dedent() function. I will use it for now on. If anyone else desires to push this, feel free, but I am satisfied.


On Thu, Nov 4, 2010 at 9:23 PM, Steven D'Aprano <> wrote:
Daniel da Silva wrote:
On several occasions I have run into code that will do something like the
following with a multiline string:

To me, this is rather ugly because it messes up the indentation of
some_func(). Suppose we could have a multiline string, that when started on
a line indented four spaces, ignores the first four spaces on each line of
the literal when creating the actual string?

In this example, I will use four quotes to start such a string.

Please no. Three quotes is large enough. Also, four quotes currently is legal: it is a triple-quoted string that begins with a quotation mark. You would be changing that behaviour and likely breaking code.

I don't think we need syntax for this, but if we do, I'd prefer to add a prefix similar to the r"" or u"" syntax. Perhaps w"" to normalise whitespace?

But as I said, I don't think we need syntax for this. I'd be happy if textwrap.dedent() became a built-in string method.

def some_func():
   x, y = process_something()
   val = """
   """.dedent() % (x, y)
   return val


Python-ideas mailing list