[Python-ideas] Advanced Line Continuation
Martin Teichmann
lkb.teichmann at gmail.com
Mon May 27 11:55:33 CEST 2013
Hello List,
often I am writing mathematical code, with rather long
formulae, spanning several lines of code. So I am
in need of line continuation, and I know that this is
currently best done by putting the line in parentheses,
as in
a = (something_long * something_longer +
something_else)
those parentheses are mathematically unnecessary.
Wouldn't it be nice if we could just write
a = something_long * something_longer +
something_else
by simply adding a new line continuation rule:
if a line ends in an operator, the next line is a continuation.
Currently, lines ending in a operator are always a
syntax error, so this rule would not break old code.
This rule is rather intuitive, as putting operators at the
end of the last line if continued is already encouraged
by PEP8.
One exception certainly is the , (comma) operator, as it
actually can be at the and of a line, so this new rule would
not apply to this operator, but as , is actually rather
different from other operators, I would not consider that
an astonishing exception.
The latter actually is a pity: with the
operator-at-end-continues-line rule we would also get rid
of the problem with long with statements, as in
with something_long as something_longer, something_cool as
something_cooler:
which cannot be nicely split.
So we could add the rule "if a line starts with 'with', even comma
continues a line", but this rule might then sound a bit too
arbitrary.
Greetings
Martin
More information about the Python-ideas
mailing list