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

There are two ways in python to catch an exception

except Exception, e: except Exception as e: 

It seems that โ€œlike eโ€ is one that should be used in the future. In which version of python has this changed? Any idea why?

+82
python exception
Feb 25 '11 at 16:26
source share
3 answers

This PEP introduces changes to help disambiguate Python grammar, simplify exception classes, simplify garbage collection for exceptions, and reduce the size of the language in Python 3.0.

PEP 3110: "Correcting Exceptions in Python 3000"

+43
Feb 25 '11 at 16:28
source share

The first suggestion on how to use it is here: http://mail.python.org/pipermail/python-dev/2006-March/062449.html . They thought it would be more intuitive to read the code.

+13
Feb 25 '11 at 16:32
source share

Short answer for why: Exception, e and Exception, TypeError difficult to distinguish from each other. Long answer: what Ignacio said.

+11
Feb 25 '11 at 16:35
source share



All Articles