Storing empties (was Re: Automatic binding of **kwargs to variables)

2005-10-31 Thread Aahz
In article [EMAIL PROTECTED], Alex Martelli [EMAIL PROTECTED] wrote: the canonical idiom when you need such distinction is: _not_there = object() def foo(bar=_not_there, baz=_not_there, bap=_not_there): if bar is _not_there: ... Other unique objects can be substituted for the 'sentinel',

Re: Automatic binding of **kwargs to variables

2005-10-30 Thread Mike Meyer
[EMAIL PROTECTED] [EMAIL PROTECTED] writes: Peter Hansen wrote: Do you mean this instead? elif name in expected_form1_kwargs and name not in kwargs: What you wrote doesn't do what you think it does... it actually tests for whether True or False is a key in kwargs, depending on

Re: Automatic binding of **kwargs to variables

2005-10-30 Thread Steven D'Aprano
On Sat, 29 Oct 2005 11:01:02 -0700, [EMAIL PROTECTED] wrote: Mike Meyer wrote: [snip] for name, value in kwargs.items(): if name in ('a', 'list', 'of', 'valid', 'keywords'): exec %s = %s % (name, value) else: raise ValueError, Unrecognized keyword +

Re: Automatic binding of **kwargs to variables

2005-10-30 Thread Steven D'Aprano
On Fri, 28 Oct 2005 15:49:12 -0700, [EMAIL PROTECTED] 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, That's easy: Just Don't Do

Re: Automatic binding of **kwargs to variables

2005-10-30 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: 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

Re: Automatic binding of **kwargs to variables

2005-10-30 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Alex Martelli wrote: 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

Re: Automatic binding of **kwargs to variables

2005-10-29 Thread Peter Otten
[EMAIL PROTECTED] 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

Re: Automatic binding of **kwargs to variables

2005-10-29 Thread Steve Holden
Peter Otten wrote: [EMAIL PROTECTED] 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

Re: Automatic binding of **kwargs to variables

2005-10-29 Thread [EMAIL PROTECTED]
Mike Meyer wrote: [snip] for name, value in kwargs.items(): if name in ('a', 'list', 'of', 'valid', 'keywords'): exec %s = %s % (name, value) else: raise ValueError, Unrecognized keyword + name Others will probably tell you that you really shouldn't be

Re: Automatic binding of **kwargs to variables

2005-10-29 Thread Peter Otten
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

Re: Automatic binding of **kwargs to variables

2005-10-29 Thread Steve Holden
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.

Re: Automatic binding of **kwargs to variables

2005-10-29 Thread Mike Meyer
[EMAIL PROTECTED] [EMAIL PROTECTED] writes: Mike Meyer wrote: [snip] for name, value in kwargs.items(): if name in ('a', 'list', 'of', 'valid', 'keywords'): exec %s = %s % (name, value) else: raise ValueError, Unrecognized keyword + name Others will

Re: Automatic binding of **kwargs to variables

2005-10-29 Thread [EMAIL PROTECTED]
Thanks everybody for their reply. I'll see what solution is best for my case and maybe follow up here. Thanks again, Lorenzo -- http://mail.python.org/mailman/listinfo/python-list

Re: Automatic binding of **kwargs to variables

2005-10-29 Thread [EMAIL PROTECTED]
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

Re: Automatic binding of **kwargs to variables

2005-10-29 Thread Peter Hansen
[EMAIL PROTECTED] wrote: 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) Do you mean this instead? elif name in

Re: Automatic binding of **kwargs to variables

2005-10-29 Thread [EMAIL PROTECTED]
FormEncode. [EMAIL PROTECTED] wrote: 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

Re: Automatic binding of **kwargs to variables

2005-10-29 Thread [EMAIL PROTECTED]
Peter Hansen wrote: Do you mean this instead? elif name in expected_form1_kwargs and name not in kwargs: What you wrote doesn't do what you think it does... it actually tests for whether True or False is a key in kwargs, depending on whether name in expected_form1_kwargs returns

Re: Automatic binding of **kwargs to variables

2005-10-29 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] 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

Re: Automatic binding of **kwargs to variables

2005-10-29 Thread [EMAIL PROTECTED]
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

Re: Automatic binding of **kwargs to variables

2005-10-29 Thread [EMAIL PROTECTED]
Alex Martelli wrote: 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. Hi Alex, the thing is that I have

Automatic binding of **kwargs to variables

2005-10-28 Thread [EMAIL PROTECTED]
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

Re: Automatic binding of **kwargs to variables

2005-10-28 Thread Mike Meyer
[EMAIL PROTECTED] [EMAIL PROTECTED] writes: 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