Automatic binding of **kwargs to variables

Alex Martelli aleaxit at yahoo.com
Sun Oct 30 01:22:14 EDT 2005


lbolognini at gmail.com <lbolognini at gmail.com> wrote:
   ...
> def foo(**kwargs):
>     expected_form1_kwargs = ["arg1", "arg2"]
> 
>     for name in expected_form1_kwargs:
>         if name not in kwargs:
>             kwargs[name]=None
> 
>     for name in kwargs:
>         if name in kwargs and name not in expected_form1_kwargs:
>             raise ValueError, "Unrecognized keyword: " + name
> 
>     print kwargs

I find this style of coding repulsive when compared to:

def foo(arg1=None, arg2=None):
    print dict(arg1=arg1, arg2=arg2)

I don't understand what added value all of those extra, contorted lines
are supposed to bring to the party.


Alex



More information about the Python-list mailing list