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 'se
[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
[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 pyt
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
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
"[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, dep
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
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
[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
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" ret
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
[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 expected_fo
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 no
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
"[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 " +
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
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 ke
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 sho
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'
[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 automa
"[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 lik
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 agains
22 matches
Mail list logo