[Tutor] Anti-Patterns in Python Programming
Steven D'Aprano
steve at pearwood.info
Sat Jul 12 04:06:06 CEST 2014
On Fri, Jul 11, 2014 at 09:56:36AM -0700, Alex Kleider wrote:
> If the part between a "with" key word and the ":" that follows it is not
> an expression (and therefore can not be protected from 'end of line' by
> enclosure in parentheses,) what is it?
A bug in the parser.
And one which is now fixed. This is using Python 3.3:
py> with (open(
... '/tmp/foo', 'w')) as f:
... f.write("Hello")
...
5
py>
Works fine, no \ line continuation needed.
The point about rules like "don't use \ line continuation" is not that
that you should never ever ever under any circumstances break them. I've
done every single one of the "Don't" rules, deliberately, not out of
ignorance, except the "from module import *" inside a function. (I have
done it at module level.) The point of such rules are to guide you
towards better practice, away from poor practice, and to make you think
good and hard before breaking the rules.
--
Steven
More information about the Tutor
mailing list