style question
Terry Hancock
hancock at anansispaceworks.com
Tue Jul 4 06:14:18 EDT 2006
Hari Sekhon wrote:
> Is it better to do:
> message = """This is line1. This is line2 This is line3\n"""
>
> or
>
> message = "This is line1.\n message = message + "This is line2\n"
> message = message + "This is line3\n"
>
> Since the first method does not follow python's clean and easy
> looking indentation structure but the second just looks crude and
> ugly anyway.
>
> If I indent the first version so the text is lined up to match code
> indentation then this comes out in the input and isn't aligned there.
There's this approach, too:
from textwrap import dedent
message = dedent(
"""
This is line1.
This is line2
This is line3
""")
The dedent function strips out leading whitespace shared
by all lines in the string.
Cheers,
Terry
--
Terry Hancock (hancock at AnansiSpaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com
More information about the Python-list
mailing list