[Python-ideas] Multi-line strings that respect indentation
Gregory P. Smith
greg at krypto.org
Sun Nov 7 19:48:22 CET 2010
I would never use a quadruple quote for this if it were ever implemented. A
better precedent would be a letter prefix to the quotes similar to what we
do for raw strings and bytes constants today. m""" perhaps.
I'm -0.5 on this.
I don't think it is a necessary feature thanks to the textwrap.dedent. But
the reason I'm not -1 is that using dedent incurs runtime cost to process
the larger string constant to generate the desired one. The best way around
this is to declare your large string constants at the module level where you
don't need to worry about dedent at all.
On Thu, Nov 4, 2010 at 6:10 PM, Stephen J. Turnbull <stephen at xemacs.org>wrote:
> Daniel da Silva writes:
> > 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
> > a line indented four spaces, ignores the first four spaces on each line
> > the literal when creating the actual string?
> We do.
> from textwrap import dedent
> def some_func():
> x, y = process_something()
> val = dedent("""\
> """) % (x, y)
> return val
> I don't think the function call is ugly enough to fix with syntax.
> Python-ideas mailing list
> Python-ideas at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas