in python: can i pass class method as and a default argument to another class method

Posted by alex on Stack Overflow See other posts from Stack Overflow or by alex
Published on 2010-05-07T19:47:44Z Indexed on 2010/05/07 19:58 UTC
Read the original article Hit count: 324

Filed under:
|

i want to to pass class method as and a default argument to another class method, so that i can re-use the method as a @classmethod

@classmethod
class foo:
 def func1(self,x):
  do somthing;
 def func2(self, aFunc = self.func1):
  # make some a call to afunc
  afunc(4)

this why when the method func2 is called within the class aFunc defaults to self.func1, but i can call this same function from outside of the class and pass it a different function at the input.

i get
NameError: name 'self' is not defined

© Stack Overflow or respective owner

Related posts about python

Related posts about class