Multi-Line Strings: A Modest Proposal
Ben Finney
ben+python at benfinney.id.au
Sat Aug 13 20:49:56 EDT 2016
Lawrence D’Oliveiro <lawrencedo99 at gmail.com> writes:
> So really, you should write it more like
>
> s = """this string continues
> on the next line."""
>
> which gets a bit ugly.
For this I have the following treatment
<URL:http://stackoverflow.com/a/2504454/70157>:
import textwrap
s = textwrap.dedent("""\
this string continues
on the next line.
""")
> So I propose adapting this convention to triply-quoted strings, as
> follows: lines where the string literal continues must begin with the
> *same* initial whitespace as the line where the string started. This
> initial whitespace is stripped off before including the rest as part
> of the string.
Fortunately, the time machine has provided that in the standard library
so you can choose to use it, even without waiting for a convention :-)
--
\ “Prediction is very difficult, especially of the future.” |
`\ —Niels Bohr |
_o__) |
Ben Finney
More information about the Python-list
mailing list