[Python-ideas] Allowing comments after line continuations
Terry Jan Reedy
tjreedy at udel.edu
Fri May 17 22:34:54 CEST 2013
On 5/17/2013 5:37 AM, Serhiy Storchaka wrote:
> I'm only -0.1 on allowing spaces after "\" line continuation. While "\ "
> causes SyntaxError at compile time it is not an issue. And trailing
> whitespaces should be avoided in any cases, after "\" or not.
Python never requires trailing whitespace, so there never a need for
trailing white space (except possibly within a multi-line string) and
therefore no need (with the exection above) of getting into the habit of
adding whitespace. Decent programming editors should have a means to
strip trailing whitespace (Idle does)*. Run that (a good habit) and
'xys\ ' is fixed. The Python repository now rejects (new) code with
trailing whitespace.
Idle's Strip Trailing Whitespace does so on all lines, even if part of a
multiline string. That may or may not be what one wants. To avoid the
stripping, appending '\n\' to the line -- which also makes the
whitespace visible and the intention clear.
s = '''abd \n\
efg'''
print(s)
# produces
abd
efg
(move cursor to detect space after d)
--
Terry Jan Reedy
More information about the Python-ideas
mailing list