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',
[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
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 +
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
[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
[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
[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
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
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
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
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.
[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
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
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
[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
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
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
[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
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
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
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
[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
22 matches
Mail list logo