What is the difference between 'except IOError as e:' and 'except IOError, e:'
Steven D'Aprano
steven at REMOVE.THIS.cybersource.com.au
Tue Nov 17 21:38:36 EST 2009
On Tue, 17 Nov 2009 20:28:16 -0600, Peng Yu wrote:
> I don't see any different between the following code in terms of output.
> Are they exactly the same ('as' v.s. ',')?
>
> try:
> raise IOError('IOError')
> except IOError as e:
> print e
This is the preferred syntax. It is used in Python 2.6 and better. It is
a syntax error in Python 2.5 and older.
> try:
> raise IOError('IOError')
> except IOError, e:
> print e
This is the obsolete syntax, used in Python 2.5 and older.
--
Steven
More information about the Python-list
mailing list