I have a structure something like this:
def foobar():
print('FOOBAR!')
class SampleClass:
foo = foobar
def printfunc(self):
self.foo()
This doesn't work because the original foobar function can't handle self
being passed to it -- it wasn't part of any class or object to begin with. Python won't let me add the @staticmethod
decorator either.
I have no control over the definition of foobar
, and I may have to override the value of foo
in subclasses.
How can I call foo, without passing the object calling it?
def foo(self): foobar()
?classmethod
.