Automatic binding of **kwargs to variables

lbolognini at gmail.com lbolognini at gmail.com
Sun Oct 30 03:21:42 CET 2005


What do u think of the following? I could keep the form schema as
expected_form1_kwargs in a separate module and import * and wrap the
kwargs check done in the for loop in a function for use in the whole
site.

The elif part is useful for checkboxes which are not passed by the
browser if they're not checked.

def foo(self, **kwargs)
    expected_form1_kwargs = [arg1, arg2]

    for name in kwargs:
        if name not in expected_form1_kwargs:
            raise ValueError, "Unrecognized keyword" + name
        elif name in expected_form1_kwargs not in kwargs.keys():
            kwargs.update(name=None)


Thanks again everybody,
Lorenzo




More information about the Python-list mailing list