exec and locals

Gregory Ewing greg.ewing at canterbury.ac.nz
Thu Feb 27 04:34:33 CET 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