function that accepts any amount of arguments?

Steve Holden steve at holdenweb.com
Thu Apr 24 13:41:34 EDT 2008


Jonathan Gardner wrote:
> On Apr 24, 5:28 am, malkarouri <malkaro... at gmail.com> wrote:
>> What's wrong with raising ZeroDivisionError (not stopping the
>> exception in the first place)?
>>
> 
> Because when I use your module, call avg (or mean) without args, I
> should see an error that says, "Hey, you have to pass at least one
> value in!"
> 
> ZeroDivisonError doesn't mean that. It means I tried to divide by
> zero. Naively, I don't see where I was dividing by zero (because I
> don't remember how to calculate the mean---that's what your code was
> for.)
> 
> ValueError does mean that I didn't pass the right kind of arguments
> in. ValueError("No items specified") would be even clearer. (Or maybe
> TypeError?)
> 
> In general, any exception thrown should be meaningful to the code you
> are throwing it to. That means they aren't familiar with how your code
> works.
> 

This is Advice. Software Engineering's next door ;-)

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list