function that accepts any amount of arguments?

bruno.desthuilliers at gmail.com bruno.desthuilliers at gmail.com
Thu Apr 24 15:12:06 EDT 2008


On 24 avr, 14:28, malkarouri <malkaro... at gmail.com> wrote:
> On Apr 24, 12:43 pm, Bruno Desthuilliers <bruno.42.desthuilli... at websiteburo.invalid> wrote:
>
> [...]
>
> > Not quite sure what's the best thing to do in the second case - raise a
> > ValueError if args is empty, or silently return 0.0 - but I'd tend to
> > choose the first solution (Python's Zen, verses 9-11).
>
> What's wrong with raising ZeroDivisionError (not stopping the
> exception in the first place)?

Because - from a semantic POV -  the real error is not that you're
trying to divide zero by zero, but that you failed to pass any
argument. FWIW, I'd personnaly write avg as taking a sequence - ie,
not using varargs - in which case calling it without arguments would a
TypeError (so BTW please s/Value/Type/ in my previous post).




More information about the Python-list mailing list