Triple-quoted strings hath not the Python-nature
Orestis Markou
orestis at orestis.gr
Tue Oct 21 05:18:34 EDT 2008
from textwrap import dedent
dedent("""\
this
is a
multi-line
string.""")
will do what you want
On Tue, Oct 21, 2008 at 9:58 AM, Lawrence D'Oliveiro
<ldo at geek-central.gen.new_zealand> wrote:
> If triple-quoted strings had the Python-nature, then they would take
> indentation into account. Thus:
>
> """this
> is a
> multi-line
> string."""
>
> would be equivalent to
>
> "this\n is a\n multi-line\nstring."
>
> and not
>
> "this\n is a\n multi-line\n string."
>
> The rule would be: the exact same whitespace characters at the beginning of
> the line on which the triple-quoted string starts must also occur at the
> start of the lines on which the string continues; these are stripped off
> and not included in the string contents. Any additional whitespace is of
> course part of the string.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
orestis at orestis.gr
http://orestis.gr
More information about the Python-list
mailing list