I have two quick questions:<br>
<br>
1) Why does sys.exit() not work in a try clause (but it does in the except clause)?<br>
<br>
>>> try:<br>
... print 1<br>
... sys.exit(0)<br>
... except:<br>
... print 2<br>
... sys.exit(0)<br>
... <br>
1<br>
2<br>
# python exited<br>
<br>
2) If opening a file fails in the below 2 cases, sys.exit(message)
prints a message in the except clause before program termination. <br>
Some use file.close() in the except clause (or in a
finally clause). It seems superflous in the below case of read and
write. (?)<br>
<br>
try:<br>
file = open('myinfile.txt', 'r')<br>
except IOError:<br>
sys.exit('Couldn't open myinfile.txt')<br>
<br>
try:<br>
file = open('myoutfile.txt', 'w')<br>
except IOError:<br>
sys.exit('Couldn't open myoutfile.txt')<br>
<br>
<br>
<br>
<br clear="all"><br><br>