I have two quick questions:

1) Why does sys.exit() not work in a try clause (but it does in the except
clause)?

try:
...    print 1
...    sys.exit(0)
... except:
...    print 2
...    sys.exit(0)
...
1
2
# python exited

2) If opening a file fails in the below 2 cases, sys.exit(message) prints a
message in the except clause before program termination.
   Some use file.close() in the except clause (or in a finally clause). It
seems superflous in the below case of read and write. (?)

       try:
           file = open('myinfile.txt', 'r')
       except IOError:
           sys.exit('Couldn't open myinfile.txt')

       try:
           file = open('myoutfile.txt', 'w')
       except IOError:
           sys.exit('Couldn't open myoutfile.txt')
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to