[Tutor] help
Ignacio Vazquez-Abrams
ignacio@openservices.net
Wed, 10 Oct 2001 16:47:01 -0400 (EDT)
On Wed, 10 Oct 2001, james middendorff wrote:
> I have been trying to get this to work but everytime I run it and type quit, it prints what I want it to but it also prints my error message as well? this is my code so far can someone explain what I am doing wrong thanks!
>
> import os, sys
> try:
> filename = raw_input("whats the file?('quit' to quit)")
> if filename == 'quit':
> print "goodbye"
> sys.exit()
> inp = open(filename, "rw")
> for line in inp.readlines():
> print line
> inp.close()
>
> except:
> IOError
> print "Error: there is no file there!"
That's because sys.exit() raises SystemExit. Use 'except IOError:' to focus
your exception handling. While you're at it, get rid of the loose 'IOError' in
your exception handler.
--
Ignacio Vazquez-Abrams <ignacio@openservices.net>