Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: functors (http://www.velocityreviews.com/forums/t319095-re-functors.html)

David Eppstein 07-02-2003 01:42 AM

Re: functors
 
In article <3jc4gvgn5rb4c4008eedg958ee594lu8p2@4ax.com>,
Tom Plunket <tomas@fancy.org> wrote:

> How can I create a functor object in Python?
>
> What I want (being a C++ coder <g>), is to be able to create an
> object that I is callable. The following is my attempt, but it
> doesn't work:

....
> class SomeClass:
> def __init__(self):
> self.countdown = Countdown()
> self.countdown.SetCallback(30, lambda s=self: s.Callback)


The error is in this line. Should be s.Callback().
As it is, your lambda is a function that returns a function object,
rather than calling it as you apparently intend.

> # I have also tried 'lambda: self.Callback'
> self.done = False


--
David Eppstein http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science


All times are GMT. The time now is 06:25 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.