errors and exception

Alan alanwilter at
Mon Aug 16 09:06:20 CEST 2010


I am using things like:

except Exception as inst:


with open("myfile.txt") as f:
    for line in f:
        print line

Things that seems to be new in python 2.6 and higher, however reading and this not clear when this new
syntaxes appeared.

My trouble is that I want to make something similar above compatible with
python 2.5, but when running python2.5 I got:

except Exception as msg:
SyntaxError: invalid syntax

If there's a way (e.g. from __future__ ..., inherited modified Exception
class, etc) that could give a solution to keep my code in python 2.6 syntax
as above but compatible with python 2.5, that would be appreciated.

Many thanks in advance,

Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
Department of Biochemistry, University of Cambridge.
80 Tennis Court Road, Cambridge CB2 1GA, UK.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list