Fwd: Should I use if or try (as a matter of speed)?

2005-07-12 Thread Dark Cowherd
I use Delphi in my day job and evaluating and learning Python over the weekends and spare time. This thread has been very enlightening to me. The comments that Joel of Joel on Software makes here http://www.joelonsoftware.com/items/2003/10/13.html was pretty convincing. But I can see from the

Re: Fwd: Should I use if or try (as a matter of speed)?

2005-07-12 Thread Christopher Subich
Dark Cowherd wrote: But one advise that he gives which I think is of great value and is good practice is Always catch any possible exception that might be thrown by a library I'm using on the same line as it is thrown and deal with it immediately. That's fine advice, except for when it's

Re: Fwd: Should I use if or try (as a matter of speed)?

2005-07-12 Thread Thomas Lotze
Christopher Subich wrote: try: f=file('file_here') except IOError: #File doesn't exist error_handle error_flag = 1 if not error_flag: do_setup_code do_stuff_with(f) which nests on weird, arbitrary error flags, and doesn't seem like good programming to me. Neither

Re: Fwd: Should I use if or try (as a matter of speed)?

2005-07-12 Thread Roy Smith
Christopher Subich [EMAIL PROTECTED] 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

Re: Fwd: Should I use if or try (as a matter of speed)?

2005-07-12 Thread Mike Meyer
Dark Cowherd [EMAIL PROTECTED] writes: But one advise that he gives which I think is of great value and is good practice is Always catch any possible exception that might be thrown by a library I'm using on the same line as it is thrown and deal with it immediately. Yuch. That sort of

Re: Fwd: Should I use if or try (as a matter of speed)?

2005-07-12 Thread Christopher Subich
Thomas Lotze wrote: Neither does it to me. What about try: f=file('file_here') except IOError: #File doesn't exist error_handle else: do_setup_code do_stuff_with(f) (Not that I'd want to defend Joel's article, mind you...) That works. I'm still not used to having