Re: Catch and name an exception in Python 2.5 +

2011-08-27 Thread Thomas Jollans
On 27/08/11 05:45, Steven D'Aprano wrote: > Thomas Jollans wrote: > >> On 26/08/11 21:56, Steven D'Aprano wrote: > >>> Is there any way to catch an exception and bind it to a name which will >>> work across all Python versions from 2.5 onwards? >>> >>> I'm pretty sure there isn't, but I thought I

Re: Catch and name an exception in Python 2.5 +

2011-08-26 Thread Steven D'Aprano
Thomas Jollans wrote: > On 26/08/11 21:56, Steven D'Aprano wrote: >> Is there any way to catch an exception and bind it to a name which will >> work across all Python versions from 2.5 onwards? >> >> I'm pretty sure there isn't, but I thought I'd ask just in case. > > It's not elegant, and I ha

Re: Catch and name an exception in Python 2.5 +

2011-08-26 Thread Thomas Jollans
On 26/08/11 21:56, Steven D'Aprano wrote: > In Python 3, you can catch an exception and bind it to a name with: > > try: > ... > except ValueError, KeyError as error: > pass > > In Python 2.5, that is written: > > try: > ... > except (ValueError, KeyError), error: > pass > > and

Catch and name an exception in Python 2.5 +

2011-08-26 Thread Steven D'Aprano
In Python 3, you can catch an exception and bind it to a name with: try: ... except ValueError, KeyError as error: pass In Python 2.5, that is written: try: ... except (ValueError, KeyError), error: pass and the "as error" form gives a SyntaxError. Python 2.6 and 2.7 accept eit