Ian Kelly wrote:
On Thu, Apr 19, 2012 at 3:33 PM, Terry Reedy <tjre...@udel.edu> wrote:
On 4/19/2012 1:15 PM, Kiuhnm wrote:
A with statement is not at the module level only if it appears inside a
function definition or a class definition.

This is true, I believe, of all statements.

Am I forgetting something?

Comprehensions (in Py3) and lambda expressions also introduce new local
scopes -- because they are abbreviated def statements. But they cannot
contain statements, only expressions, in that new scope.

Syntactically, that's true.  However, lambdas and comprehensions are
just functions and generator functions under the hood, so in principle
there is nothing preventing with blocks from being injected into their
byte code.

Which would still not be at the module level.

~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to