exec and locals

Gregory Ewing greg.ewing at canterbury.ac.nz
Thu Feb 27 06:29:35 EST 2014


Steven D'Aprano wrote:
> On Thu, 27 Feb 2014 16:34:33 +1300, Gregory Ewing wrote:
> 
>>Why not just use this version all the time? It should work in both 2.x
>>and 3.x.
> 
> Because that's yucky. It's an aesthetic thing: when supported, I want the 
> Python interpreter to manage the context manager.

More yucky than wrapping the Py3 version in an
exec? To my way of thinking, that cancels out any
elegance that might have been gained from using
a with-statement.

Do you really need to use the context manager
at all? Could you just write the try-statement
that you would have written in Py2 if you
didn't have a context manager?

-- 
Greg



More information about the Python-list mailing list