is parameter an iterable?

Jean-Paul Calderone exarkun at
Tue Nov 15 20:34:36 CET 2005

On 15 Nov 2005 11:26:23 -0800, py <codecraig at> wrote:
>Dan Sommers wrote:
>> Just do it.  If one of foo's callers passes in a non-iterable, foo will
>> raise an exception, and you'll catch it during testing
>That's exactly what I don't want.  I don't want an exception, instead I
>want to check to see if it's an iterable....if it is continue, if not
>return an error code.

Error codes are not the common way to do things in Python.  Exceptions are.  There's generally no reason to avoid exceptions.  Error codes allow errors to pass silently, which leads to bugs that nobody notices for long periods of time.

You should let the exception be raised.  You shouldn't try to return an error code.

>I can't catch it during testing since this is going to be used by 
>other people.

Then they'll catch it during their testing >:)  If you return an error code instead, they are just as likely to pass in bad data, and even *more* likely to not see that an error has occurred, causing their programs to be incorrect.


More information about the Python-list mailing list