style question

Duncan Booth duncan.booth at invalid.invalid
Mon Jun 26 06:01:37 EDT 2006


Hari Sekhon wrote:

> 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 you want indented and pretty is important to you:

>>> from textwrap import dedent as D
>>> message = D("""\
           This is line1.
           This is line2
           This is line3
           """)
>>> message
'This is line1.\nThis is line2\nThis is line3\n'

Usually though I would just make sure that long strings are declared at 
module level and not indent them. The backslash after the opening quotes 
stops the first line being indented differently:

message = """\
This is line1.
This is line2
This is line3
"""



More information about the Python-list mailing list