class C():
def print_once(self):
print(self)
def print_twice(self):
print(self, self)
c = C()
setattr(c, 'print_twice', print_twice)
c.print_once()
c.print_twice()
>>> <__main__.C object at 0x0000028116795108>
>>> TypeError: print_twice() missing 1 required positional argument: 'self'
I'm aware setattr(C, ..)
does the trick, but this affects future and concurrent instances of C
and is undesired. Can print_twice
be set only to c
, such that self
is passed automatically just like to print_once
?