Soni L. writes:
> Explicit is better than implicit.
>
> and \z is more explicit than #cont
It's not more explicit. Line continuation in a string literal is
perfectly explicit and easy to explain *exactly*: "omit the '\' and
the following newline from the string being constructed". You could
argue that '\z' is more easily visible ("readable" if you like), but
not that it's more explicit.
The simplest form of '\z' is "almost easy" to explain exactly ("omit
the following newline and all leading whitespace on the next line").
Complication enters when we ask, "but what happens if the character
following '\z' is not a newline?"
But more generally, string dedenting is hard to explain with much
precision, let alone exactly, except in (pseudo)code. '\z' would be
even more complicated than textwrap.dedent, because it would apply
line by line. Would the indentation that is stripped be string-wide
(so that '\z' could work like RFC 822 folding with the intended
whitespace at the *left* margin, where it's easy to see), or would
each '\z' just strip all the indentation on the next line? Maybe '\z'
should replace all the surrounding whitespace with a single space?
I kinda like the string-wide idea, but
s = textwrap.dedent("""\
This\
is\
a\
silly\
example\
of\
a\
dedented\
and\
folded\
string.\
""")
assert s == "This is a silly example of a dedented and unfolded string."
works for me, specifically in real examples where *occasionally* for
some reason I want to fold a long line. That is, although the
trailing '\' at the right margin is not so easy to see, the extra
space at the left margin of the next line is easy to see (at least
with a reasonable font).
Of course,
s = "This"
" is"
" a"
...
works even better when what you want is an unfolded one-line string.
Steve