[Python-ideas] Idea for new multi-line triple quote literal
Ron Adam
ron3200 at gmail.com
Mon Jul 1 15:58:33 CEST 2013
On 07/01/2013 05:52 AM, Markus Unterwaditzer wrote:
> I rather want to write code that looks a lot more like this:
>
> def foo():
> return """
> look at me
> i am cool
> i can do indentation
> """
>
> So the first line would have four spaces at the beginning, the second eight,
> the third four again. The "\n" character after "indentation" would be the
> last character in the string.
Currently to get what you want you need to use both dedent and indent.
>>> print(indent(dedent("""
... look at me
... I am cool
... I can do indentation
... """), prefix=" "))
look at me
I am cool
I can do indentation
Since indent is already in textwrap and works differently, I think 'margin'
would be a good method name to set the left margin.
def foo():
return """\
look at me
i am cool
i can do dedent.
""".margin(4)
I think this fits a much more common usage pattern, and we won't need to
add two methods to do what you want here.
A dedent method could take a 'margin' argument..
s.dedent(margin=4)
But I prefer just calling it margin.
Cheers,
Ron
More information about the Python-ideas
mailing list