try/except/else/finally problem

Ed Jensen ejensen at visi.com
Thu Jun 28 13:54:37 EDT 2007


I'm using:

Python 2.3.2 (#1, Oct 17 2003, 19:06:15) [C] on sunos5


And I'm trying to execute:

#! /usr/bin/env python

try:
    f = file('test.txt', 'r')
except IOError:
    print 'except'
else:
    print 'else'
finally:
    print 'finally'


And the results are:

  File "./test.py", line 9
    finally:
          ^
SyntaxError: invalid syntax


What am I doing wrong?

Thanks in advance for any help.



More information about the Python-list mailing list