Automatic binding of **kwargs to variables

lbolognini at gmail.com lbolognini at gmail.com
Fri Oct 28 18:49:12 EDT 2005


Hi all,

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

I was adviced against doing it by adding stuff to locals such as:

locals()["x"] = 5

since the Python Docs say:

Warning: The contents of this dictionary should not be modified;
changes may not affect the values of local variables used by the
interpreter.

Is there a way to do this? Maybe object.__setattr__() or something that
involves metaclasses?

As I might go touching something that I shouldn't (like locals()) I'd
like some advice from you before deciding which way to go.


Thanks,
Lorenzo




More information about the Python-list mailing list