exec and locals

Gregory Ewing greg.ewing at canterbury.ac.nz
Wed Feb 26 22:34:33 EST 2014


Steven D'Aprano wrote:
>     except SyntaxError:
>         def inner():
>             # manually operate the context manager
>             call context manager __enter__
>             try:
>                 try:
>                     return something
>                 except:  # Yes, a bare except. Catch EVERYTHING.
>                     blah blah blah
>             finally:
>                     call context manager __exit__

Why not just use this version all the time? It should
work in both 2.x and 3.x.

-- 
Greg



More information about the Python-list mailing list