2021-03-09 17:00:47 +03:00
|
|
|
class Foo:
|
|
|
|
def bar(self):
|
|
|
|
print("Called bar")
|
|
|
|
|
|
|
|
let f = Foo()
|
|
|
|
f.bar()
|
|
|
|
|
|
|
|
def other(instance):
|
|
|
|
print("Called other")
|
|
|
|
|
|
|
|
def noargs():
|
|
|
|
print("Uh oh, binding will work but call will fail.")
|
|
|
|
|
|
|
|
Foo.other = other
|
|
|
|
Foo.noargs = noargs
|
|
|
|
|
2022-08-06 06:20:04 +03:00
|
|
|
print('<bound method \'other' in str(f.other))
|
2021-03-09 17:00:47 +03:00
|
|
|
f.other()
|
|
|
|
|
2022-08-06 06:20:04 +03:00
|
|
|
print('<bound method \'noargs' in str(f.noargs))
|
2021-03-09 17:00:47 +03:00
|
|
|
try:
|
|
|
|
f.noargs()
|
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
|
|
|
|
|
|
|
class SomethingCallable():
|
|
|
|
def __call__(self):
|
|
|
|
print("I can be called")
|
|
|
|
|
|
|
|
Foo.callable = SomethingCallable()
|
|
|
|
|
|
|
|
f.callable()
|