Automatic binding of **kwargs to variables

Steve Holden steve at holdenweb.com
Sat Oct 29 15:21:35 EDT 2005


Peter Otten wrote:
> Steve Holden wrote:
> 
> 
>>>Why don't you just change the method signature to foo(self, x, y, z,
>>>whatever, **kwargs)?
> 
> 
>>Probably because values are then required for those arguments. Plus it's
>>a lot of work to specify "a very long list", and the list will also need
>>maintaining.
> 
>  
> Note that I kept the **kwargs argument. He would only have to specify
> variables that are actually used in foo(), and these need maintaining
> anyway. As to optional arguments, you can provide default values. Checking
> for those is easier and safer than using local variables that may not be
> bound or accidentally refer to a global.
> 
Now I think I understand your intention better. Further discussion would 
be flogging horse already dead for several days.

> # e. g.
> missing = object() # if None is a valid state of whatever
> def foo(self, whatever=missing, **kwargs):
>     if whatever is not missing:
>         # use whatever
> 
> 
>>I must, however, agree with Mike's advice: it's unwise to try and
>>pollute a function's namespace with arbitrary variables. Some kind of
>>bunch-like object would seem to be the most satisfactory way to go.  
> 
> 
> Using a bunch doesn't remove the necessity of an existence-test either (for
> optional attributes).
> 
No more it does.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list