[Tutor] sys.exit() syntax error

John M. Purser jmpurser at comcast.net
Tue Apr 6 05:34:16 EDT 2004


Yep, this is a self kicker.

The problem is in the line:
except: IOError

try this instead:
except IOError:

John Purser

-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org]On
Behalf Of Gerald Wann
Sent: Tuesday, April 06, 2004 3:04 AM
To: tutor at python.org
Subject: [Tutor] sys.exit() syntax error


Hi -

The answer to this is probably so trivial that i'll kick myself for 
asking... ;-)

i'm trying to use the sys.exit() function inside an error trap block and 
the interpreter keeps telling me there's a syntax error e.g.

import sys

try:
	open(file)
except: IOError
	print 'blah'
	print 'blah'
	sys.exit()

python doesn't like this... and says there's a syntax error at the 
sys.exit() line

however, when i dedent the sys.exit() call outside the except: block, it 
runs just fine, (except for the fact that it shuts the whole thing down ;-)

What am i missing here?

I'm using Komodo 2.5 IDE and python 2.2.3

TIA

Jerry


_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor




More information about the Tutor mailing list