Fwd: Should I use "if" or "try" (as a matter of speed)?
Roy Smith
roy at panix.com
Tue Jul 12 16:53:49 EDT 2005
Christopher Subich <spam.csubich+block at block.subich.spam.com> wrote:
>try:
> f = file('file_here')
> do_setup_code
> do_stuff_with(f)
>except IOError: # File doesn't exist
> error_handle
It's also a good idea to keep try blocks as small as possible, so you
know exactly where the error happened. Imagine if do_setup_code or
do_stuff_with(f) unexpectedly threw an IOError for some reason totally
unrelated to the file not existing.
More information about the Python-list
mailing list