Argument of the bool function
Ian Kelly
ian.g.kelly at gmail.com
Mon Apr 25 19:44:38 EDT 2011
On Mon, Apr 25, 2011 at 3:28 PM, Thomas Rachel
<nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de>
wrote:
> Am 25.04.2011 16:29, schrieb Thomas Rachel:
>>> 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())
>> Or yet even better:
>> class Job(object):
> def __init__(self, target, *args, **kwargs):
> self.target = lambda: target(*args, **kwargs)
> def __call__(self):
> return self.target()
>> in order to do
>> actions.append(Job(function, val))
> actions.append(Job(function, x=val))
from functools import partial
actions.append(partial(function, val))
actions.append(partial(function, x=val))
Cheers,
Ian
More information about the Python-list
mailing list