Re: Automatic binding of **kwargs to variables
- From: "bonono@xxxxxxxxx" <bonono@xxxxxxxxx>
- Date: 29 Oct 2005 22:30:15 -0700
Don't know about this particular case but sometimes, I don't want to
have a default argument value. That is, argument not there is different
from argument = None. Though in general, I prefer the None as special
meaning coding style. But even python's builtin function prefers to
distinguish between "not there" and None.
Alex Martelli wrote:
> lbolognini@xxxxxxxxx <lbolognini@xxxxxxxxx> 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
.
- Follow-Ups:
- Re: Automatic binding of **kwargs to variables
- From: Alex Martelli
- Re: Automatic binding of **kwargs to variables
- References:
- Automatic binding of **kwargs to variables
- From: lbolognini@xxxxxxxxx
- Re: Automatic binding of **kwargs to variables
- From: lbolognini@xxxxxxxxx
- Re: Automatic binding of **kwargs to variables
- From: Alex Martelli
- Automatic binding of **kwargs to variables
- Prev by Date: Re: Automatic binding of **kwargs to variables
- Next by Date: Re: Automatic binding of **kwargs to variables
- Previous by thread: Re: Automatic binding of **kwargs to variables
- Next by thread: Re: Automatic binding of **kwargs to variables
- Index(es):