2to3 fixer to convert try .. except .. block

Posted by Sridhar Ratnakumar on Stack Overflow See other posts from Stack Overflow or by Sridhar Ratnakumar
Published on 2010-05-03T22:15:05Z Indexed on 2010/05/03 22:18 UTC
Read the original article Hit count: 312

Filed under:
|
|
|

I have a Python2 project with lots of try .. except .. blocks like this:

try:
    [...]
except SomeException, e:
    # do something with `e`

To port them all to Python 3 (and still have the code run Python >=2.6), I have to manually change each and every one of them to the following:

try:
    [...]
except SomeException, e:
    _, e, _ = sys.exc_info()
    # do something with `e`

Can this be automated using 2to3? If so, how?

© Stack Overflow or respective owner

Related posts about python

Related posts about python-3.x