I have a simple class:
class MyClass():
...
def function(self):
return self.transform(**self.kwargs)
def transform(self, **kw):
''' main '''
return 1
I tried to override the transform
method, but when it's called by the function
method it fails.
def t(self, **kw):
return 2
instance = MyClass()
instance.transform = t
instance.function()
> missing 1 required positional argument: 'self'
weird right? I thought the self.
denotes that it's passing the self
in as the first argument automatically...?
So it works if I don't include self.
def t(**kw):
return 2
instance = MyClass()
instance.transform = t
instance.function()
> 2
But that means my t
function can't access any of the attributes of the object. Can you help me?
Of course I could create a new class that derives from MyClass, but I don't want to. Any other way to inject a method to an object that can access the objects memory?