I wonder if anything like this is possible in Python. Say that in a library, there is a class X
defined with methods a
, b
and c
:
class X:
def a(self):
...
def b(self):
...
def c(self):
...
I would like to add a method custom
into the class X
(so that I can then call X().custom()
) without modifying the library code.
I know I could do something like
def custom(self):
...
X.custom = custom
but doing it this way does not look very nice.
Is there any more intelligent way of achieving what I want (for example similar to impl
on structs in Rust)?