In Python, what's the difference between 'except Exception as e' and 'except Exception, e'

PythonException

Python Problem Overview


In python, there are two ways to catch an exception

except Exception, e:

except Exception as e:

It seems like 'as e' is the one to use going forward. In what version of python did this change? Any idea why?

Python Solutions


Solution 1 - Python

> This PEP introduces changes intended to help eliminate ambiguities in Python's grammar, simplify exception classes, simplify garbage collection for exceptions and reduce the size of the language in Python 3.0.

http://www.python.org/dev/peps/pep-3110/">PEP 3110: "Catching Exceptions in Python 3000"

Solution 2 - Python

Short answer for the why: Exception, e and Exception, TypeError are hard to tell apart. Long answer: what Ignacio said.

Solution 3 - Python

The first proposal for using the "as" is here: http://mail.python.org/pipermail/python-dev/2006-March/062449.html. They thought it would be more intuitive to read the code

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNathanView Question on Stackoverflow
Solution 1 - PythonIgnacio Vazquez-AbramsView Answer on Stackoverflow
Solution 2 - PythonnmichaelsView Answer on Stackoverflow
Solution 3 - PythonFábio DinizView Answer on Stackoverflow