function that accepts any amount of arguments?

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Mon Apr 28 09:26:20 EDT 2008


Lie a écrit :
> On Apr 25, 2:12 am, "bruno.desthuilli... at gmail.com"
> <bruno.desthuilli... at gmail.com> wrote:

(...)

>> 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).
> 
> The problem with passing it as a sequence is, if you want to call it,
> you may have to wrestle with this odd looking code:
> avg((3, 4, 6, 7))
> 
> rather than this, more natural code:
> avg(3, 4, 6, 7)

Possibly. Yet my experience is that, most of the time, such a function 
will be called with an already existing sequence, so the most common 
call scheme is

   res = avg(some_sequence)

which is more natural than

   res = avg(*some_sequence)

!-)


> And FWIW, the OP asked if it is possible to pass variable amount of
> arguments,  avg is just a mere example of one where it could be used
> not where it could be best used.

Indeed - but that's not what I was commenting on.



More information about the Python-list mailing list