how best to check a value? (if/else or try/except?)
John Salerno
johnjsal at NOSPAMgmail.com
Fri Jul 28 09:42:02 EDT 2006
Nick Vatamaniuc wrote:
> John,
>
> The way I do it is, is I ask myself 'is there a more common (basic)
> base between the code paths or do they both have about a 50/50 chance
> on average?' or 'will one code path be taken during an error and the
> other one during the normal processing?'. If there is a clear single
> common/usual/basic case or I try to detect an error I use 'try/except',
> if it could go either way on average I use 'if'.
Thanks, that's something good to think about. This issue came up once
before and I remember someone saying something like "you're using a
try/except statement, but i wouldn't really consider that situation
'exceptional'", so thinking of it in your terms might help a lot.
More information about the Python-list
mailing list