[zz]Python try…except comma vs 'as' in except
http://stackoverflow.com/questions/2535760/python-try-except-comma-vs-as-in-except
What is the difference between ',' and 'as' in except statements, eg:
try:
pass
exceptException, exception:
pass
and:
try:
pass
exceptExceptionas exception:
pass
Is the second syntax legal in 2.6? It works in CPython 2.6 on Windows but the 2.5 interpreter in cygwin complains that it is invalid.
If they are both valid in 2.6 which should I use?
http://www.python.org/dev/peps/pep-3110/
Summary: In Python 2.6+, use the as
syntax, since it is far less ambiguous.
the "as" syntax is the preferred one going forward, however if you're code needs to work with older Python versions (2.6 is the first to support the new one) then you'll need to use the comma syntax.