Argument of the bool function

Thomas Rachel nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de
Mon Apr 25 10:29:34 EDT 2011


Am 10.04.2011 18:21, schrieb Mel:
> Chris Angelico wrote:
>>> Who would use keyword arguments with a function that takes only one arg
>> anyway?
>> It's hard to imagine. Maybe somebody trying to generalize function calls
> (trying to interpret some other language using a python program?)
>> # e.g. input winds up having the effect of ..
> function = bool
> name = 'x'
> value = 'the well at the end of the world'
> ## ...
> actions.append ((function, {name:value}))
> ## ...
> for function, args in actions:
> results.append (function (**args))

Wrong structure.
Better do
function = bool
value = 'the well at the end of the world'
## ...
actions.append((function, (value,), {}))
## ...
for function, args, kwargs in actions:
 results.append(function(*args, **kwargs))
or maybe even better (taking care for closures):
function = bool
value = 'the well at the end of the world'
## ...
actions.append(lambda val=value: function(val))
## ...
for function in actions:
 results.append(function())
>> Not something I, for one, do every day. But regularity in a language is
> good when you can get it, especially for abstract things like that.
>> I can sort of guess that `dir` was perhaps coded in C for speed and doesn't
> spend time looking for complicated argument lists.
>> Python is a pragmatic language, so all the rules come pre-broken.
>>> 	Mel.



More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /