Pre-PEP: d-string / Dedented Multiline Strings with Optional Language Hinting

I’m not against, but I consider the d-string superior, for a simple reason: IMO Python should have that by default. And there’s more.

My idea is not a new idea. I discovered this post:

I quote some posts, that add really strong points:

Really cool indeed. I love it. :heart_eyes:

Don’t know if it’s a good idea to dedent before f-strings are applied. What if the f-string adds newlines and indentations?

For the rest, I completely agree.

This is exactly my main point. Having to write d""" will be boring, since the best was it did it by default. But the ship is sailed.

On the contrary, having to write:

"""
    hello
    my
    friend
""".dedent()

it’s not only more boring, but absolutely less powerful, per before quotes.

At this point, instead of having yet-another-method similar to textwrap.dedent(), I prefer to have nothing. We can instead improve textwrap.dedent() with an optional kwarg.

Just my 0.0.1 cents.

2 Likes