[Python-ideas] Idea for new multi-line triple quote literal

Robert Kern robert.kern at gmail.com
Tue Jul 2 12:32:22 CEST 2013


On 2013-07-02 03:04, Steven D'Aprano wrote:
> On Mon, Jul 01, 2013 at 06:22:25PM +0200, Philipp A. wrote:
>> 2013/7/1 Guido van Rossum guido at python.org
>>
>> That‘s a compelling argument. Let’s do it. (Assuming the definition of
>> exactly how to indent or dedent is not up for discussion — if there
>> are good reasons to disagree with textwrap now's the time to bring it
>> up.)
>>
>> I don’t know if it’s a good reason, but I’m of the opinion that the
>> required backslash at the beginning of to-be-dedented string is strange:
>
> It's not *required*. It's optional. You can live with an extra blank
> line:
>
> s = """
>      first line
>      second line ... """
>
> or you can manually indent the first line:
>
> s = """    first line
>      second line ... """
>
> or you can slice the string before calling dedent, or, in my
> opinion the neatest and best solution, just escape the opening
> newline with a backslash:
>
> s = """\
>      first line
>      second line ... """
>
> But in any case, I don't like the idea of making the proposed dedent
> method be a DWIM "format strings the way I want them to be formatted"
> method. It's called "dedent", not "dedent and strip leading newlines".
>
> I'm okay in principle with dedent taking additional arguments to
> customize the behaviour, such as amount of whitespace to keep or a
> margin character, so long as the default with no args matches
> textwrap.dedent.

How about an option to ignore the first line?

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco



More information about the Python-ideas mailing list