[Python-ideas] Syntax for dedented strings
Bruce Leban
bruce at leapyear.org
Tue Aug 16 23:42:10 CEST 2011
This has been discussed a few times in the past.
http://mail.python.org/pipermail/python-ideas/2011-May/010207.html
triple-quoted
strings and indendation
http://mail.python.org/pipermail/python-ideas/2010-November/008589.html
Multi-line
strings that respect indentation
--- Bruce
Follow me: http://www.twitter.com/Vroo http://www.vroospeak.com
On Tue, Aug 16, 2011 at 2:33 PM, Michael Foord <fuzzyman at gmail.com> wrote:
> Hello all,
>
> I'm sure this will be shot down [1], but it annoys me often enough that I'm
> going to suggest it anyway. :-)
>
> A recent tweet of Raymond's reminded me how useful textwrap.dedent() is for
> dedenting triple quoted strings in code blocks:
>
> def function():
> this_string = textwrap.dedent("""\
> Here is some indented text.
> that dedent will handle for us."""
> )
>
> Unfortunately that doesn't work for docstrings as they must be string
> literals. It is compounded by the fact that you can't even create the
> docstring for a class and manually assign it later. (Why not? But that's
> another issue...)
>
> How about *another* string prefix for dedented strings:
>
> class Thing(object):
> d"""
> This text will be,
> nicely dedented,
> thank you very much.
> """"
>
> All the best,
>
> Michael Foord
>
> [1] Because of the -100 rule as much as anything else, which applies doubly
> to features requiring new syntax
> https://blogs.msdn.com/b/ericgu/archive/2004/01/12/57985.aspx
>
> --
>
> http://www.voidspace.org.uk/
>
> May you do good and not evil
> May you find forgiveness for yourself and forgive others
> May you share freely, never taking more than you give.
>
>
> -- the sqlite blessing http://www.sqlite.org/different.html
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110816/7ce80fd8/attachment.html>
More information about the Python-ideas
mailing list