Prevent self being passed to a function stored as a member variable?

Sandra-24 sandravandale at yahoo.com
Mon Sep 4 12:39:32 EDT 2006


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

I thought maybe you could do this:

class Foo(object):
   def __init__(self, callback):
      self.func = staticmethod(callback)  # Error, staticmethod not
callable

Somebody (maybe everybody other than myself) here must know?

Thanks,
-Sandra




More information about the Python-list mailing list