Steven D'Aprano wrote:
> That's broken. 
> 
> Imagine that somewhere in main() the following is called:
> 
> D = {"a": "apple", "b": "bicycle", "c": "cat"}
> print D["aardvark"]
> 
> Your code now prints "That number is way too big!". That's not good.
> 
> try...except blocks should, as a general rule, cover only the smallest
> amount of code that they need to.

Hi Steven,

Point taken and I think your solution better addresses the root of the 
problem. However, the OP said he wanted to print out that error message 
whenever the interpreter came across any IndexError. So I gave him what 
he wanted. I guess he needs to be more careful what he wishes for ;)

-Farshid
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to