Assign external function to class variable in Python
问题 I am trying to assign a function defined elsewhere to a class variable so I can later call it in one of the methods of the instance, like this: from module import my_func class Bar(object): func = my_func def run(self): self.func() # Runs my function The problem is that this fails because when doing self.func() , then the instance is passed as the first parameter. I've come up with a hack but seems ugly to me, anybody has an alternative? In [1]: class Foo(object): ...: func = lambda *args: