Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #4008

Re: Argument of the bool function

References (2 earlier) <4da1a8b5$0$23679$426a74cc@news.free.fr> <mailman.190.1302440567.9059.python-list@python.org> <inslea$p6d$1@speranza.aioe.org> <ip40gf$i0o$1@r03.glglgl.eu> <ip4p1v$gmf$1@r03.glglgl.eu>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2011-04-25 17:44 -0600
Subject Re: Argument of the bool function
Newsgroups comp.lang.python
Message-ID <mailman.824.1303775109.9059.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Apr 25, 2011 at 3:28 PM, Thomas Rachel
<nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar


Thread

Re: Argument of the bool function Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-04-25 16:29 +0200
  Re: Argument of the bool function Chris Angelico <rosuav@gmail.com> - 2011-04-26 05:33 +1000
    Re: Argument of the bool function Paul Rubin <no.email@nospam.invalid> - 2011-04-25 16:26 -0700
      Re: Argument of the bool function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-26 02:38 +0000
  Re: Argument of the bool function Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-04-25 23:28 +0200
    Re: Argument of the bool function Ian Kelly <ian.g.kelly@gmail.com> - 2011-04-25 17:44 -0600

csiph-web