Prevent self being passed to a function stored as a member variable?
Qiangning Hong
hongqn at gmail.com
Mon Sep 4 12:52:00 EDT 2006
On 4 Sep 2006 09:39:32 -0700, Sandra-24 <sandravandale at yahoo.com> wrote:
> How can you prevent self from being passed to a function stored as a
> member variable?
>
> class Foo(object):
> def __init__(self, callback):
> self.func = callback
>
> f =Foo(lambda x: x)
> f.func(1) # TypeError, func expects 1 argument, recieved 2
Do you really get that error? I got the following in my python shell:
.>>> class Foo(object):
.... def __init__(self, callback):
.... self.func = callback
....
.>>> f = Foo(lambda x: x)
.>>> f.func(1)
1
More information about the Python-list
mailing list