critique this little script, if you like
arv.nntp at gmail.com
Mon May 1 17:45:44 CEST 2006
John Salerno escribió:
> Alexis Roda wrote:
>> > The
>> > try block seems nicer because it doesn't have such an ugly-looking
>> > to make.
> Why do you think that this try block is preferred over what I have (if I
> were to stick with the try block)?
My example has nothing to do with your script, apart from trying to
illustrate why I think you should use "if" instead of "try" with a kind
of "reductio ad absurdum" reasoning.
To me i == 0 seems as ugly as len(sys.argv) == 1 (*), so, according to
your statement about ugly checks, you should avoid code like:
if i == 0 :
and write something like:
x = 1 / i
except ZeroDivisionError :
but probably you wouldn't, the "if" block seems more "natural" than the
convoluted "try" block, so ...
(*) len(sys.argv) == 1 is exactly the same as len(sys.argv) - 1 == 0
More information about the Python-list