Velocity Reviews

Velocity Reviews (
-   Python (
-   -   Re: functors (

David Eppstein 07-02-2003 01:42 AM

Re: functors
In article <>,
Tom Plunket <> 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
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.