reducing if statements and error handling

Alex Martelli aleax at aleax.it
Tue Aug 21 12:20:09 EDT 2001


"Karthik Gurumurthy" <karthikg at aztec.soft.net> wrote in message
news:mailman.998401650.6829.python-list at python.org...
>
> i was just wondering, if the purpose of the method is just to check wether
> it is a number or not
> it s'd either return a true / false ( +ve number / -ve number)
> It s'd not throw an exception if it does'nt find it to be a number.
> I feel this is not an "exceptional" situation at all for this method.

The fact that a situation is not particularly exceptional is
no reason (in Python) to avoid raising an exception.  Don't
let the practice of other languages such as C++ and Java mess
up your Python style!

E.g., up to Python 2.1, whenever you code:
    for x in asequence:
        print x
there will ALWAYS be an exception raised -- that's how the
for statement knows the sequence is finished, by getting
an IndexError exception from asequence[i] for some i.  Far
from being 'exceptional', this must ALWAYS happen in ANY
for statement that's not interrupted by break, return, or
some other raise.  See -- exceptions are NOT only for
exceptional cases, *in Python*.


Alex






More information about the Python-list mailing list