Automatic binding of **kwargs to variables

Steve Holden steve at holdenweb.com
Sat Oct 29 13:14:11 EDT 2005


Peter Otten wrote:
> lbolognini at gmail.com wrote:
> 
> 
>>I have a very long list of parameters coming from a web form to my
>>method foo(self, **kwargs)
>>
>>I would like to avoid manually binding the variables to the values
>>coming through the **kwargs dictionary, just to keep the code cleaner,
>>I'd like to bind them automatically
> 
> 
> Why don't you just change the method signature to foo(self, x, y, z,
> whatever, **kwargs)?
> 
> Peter
> 
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.

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.

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