1, what is the callback function, feel good complex?? What is the meaning of existence?
callback function: A function called by a function pointer. If you pass the pointer (address) of the function as an argument to another function, when the pointer is used to invoke the function it points to, we say this is a callback function.
As the following example 1: Source https://www.cnblogs.com/hainan-zhang/p/6222552.html
defClean1 (times):"""just pretend to sweep the floor. Param Times: Count return None""" Print('sweep Times completed:', Times)defclean2 (times):"""pretend to wash the hood param times: Return:none""" Print('Number of wash Hoods:', Times)defCall_clean (times,function_name):"""This is very important, that is, the business system of domestic companies, what business must be here to say this is the core of the implementation of the callback function param times: number param function_name: callback function name return: The result of the call functions
""" returnfunction_name (Times) Call_clean (10,CLEAN2)#Call_clean (10,clean2)
This example describes the use of callback functions, without indicating the meaning of the callback function. This is not as good as calling the Clean2 function directly 10 times.
Here's another one on the Internet, example 2:http://blog.csdn.net/ma52103231/article/details/61432120
Look a little confused, difficult, change a
classCallback:def __init__(self,instance,function_name): Self.instance=instance Self.function_name=function_namedefAction (self,params): Self.instance.__getattribute__(Self.function_name) (params)classTest:def __init__(self): SELF.CLB=NonedefRegister (SELF,CLB): SELF.CLB=CLBdefdo_test (self): params=[] self.clb.action (params)classApi:def __init__(self,test_instance): Test_instance.register (Callback (self,self.function.__name__)) deffunction (self,params):Print('function') T=Test () a=Api (t) t.do_test ()#function
Example 3:http://blog.csdn.net/ma52103231/article/details/61432120
Python callback function