How to do *args, **kwargs properly
Max M
maxm at mxm.dk
Tue Oct 11 10:02:31 EDT 2005
Lasse Vågsæther Karlsen wrote:
> Max M wrote:
> So what you're saying is that instead of:
>
> def fn(*values, **options):
>
> I should use:
>
> def fn(values, cmp=cmp):
>
> in this specific case?
>
> and then instead of:
>
> fn(1, 2, 3, cmp=...)
>
> this:
>
> fn([1, 2, 3], cmp=...)
Precisely. Sometimes you need different interfaces for a method. In that
case it is fine.
But if you are just doing it instead of passing sequences, you are just
(ab)using the * and ** operators.
The method definition, like any python code, is made for humans not
machines. The more obvious you can make the function definition, the
happier anyone will be.
--
hilsen/regards Max M, Denmark
http://www.mxm.dk/
IT's Mad Science
More information about the Python-list
mailing list