任何定义的函数都可以通过简单地使用其名称来传递,而无需
()在调用末尾添加:
def my_callback_func(event): # do stuffo = Observable()o.subscribe(my_callback_func)
其他示例用法:
class CallbackHandler(object): @staticmethod def static_handler(event): # do stuff def instance_handler(self, event): # do stuffo = Observable()# static methods are referenced as <class>.<method>o.subscribe(CallbackHandler.static_handler)c = CallbackHandler()# instance methods are <class instance>.<method>o.subscribe(c.instance_handler)# You can even pass lambda functionso.subscribe(lambda event: <<something involving event>>)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)