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

Christopher Subich spam.csubich+block at block.subich.spam.com
Tue Jul 12 22:34:44 EDT 2005


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 'else' available like that.  I 
wonder how Joel advocates managing in C++-likes that don't have a 
try/catch/else semantic.



More information about the Python-list mailing list