Open maxalbert opened 8 years ago
@maxalbert Thanks for this suggestion. I'll think about adding a reference to this to the guide.
The first form does not work, because dedent
only removes common leading white space. Here, there is no common leading whitespace, because the first line has no leading whitespace at all.
Good catch @olivren, thanks for pointing this out. (I'm surprised I didn't re-execute the snippets when posting this to ensure they both behaved correctly. 😂)
In section "Implicit multi-line strings vs triple-quote
"""
" you can get the best of both worlds (avoiding ugly new-lines as well as keeping indentation) by usingtextwrap.dedent()
, for example:You can also achieve more compact spacing if you start the string in the second line (but then you need to add a backslash after the opening triple-quote to avoid a leading newline):
I slightly prefer the second one, but I guess it's a matter of taste.