perl 和 python中的回调函数
来源:互联网 发布:android批注涂鸦源码 编辑:程序博客网 时间:2024/05/21 08:49
就是向函数的参数为 一个函数的引用sub callback1 { ......}sub callback2 { ......}sub run { my $func_ref = shift; ..... ....}if (a>b) { run(\&callback1);}else { run(\&callback2);}def my_callback(input): print "function my_callback was called with %s input" % (input,)def caller(input, func): func(input)for i in range(5): caller(i, my_callback)C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/cookbook/a3.pyfunction my_callback was called with 0 inputfunction my_callback was called with 1 inputfunction my_callback was called with 2 inputfunction my_callback was called with 3 inputfunction my_callback was called with 4 inputdef apply_async(func, args, callback):# Compute the result result = func(*args)# Invoke the callback with the result callback(result)def print_result(result): print('Got:', result)def add(x, y): return x + y*2print apply_async(add, (2, 3), print_result)C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/cookbook/a4.py('Got:', 8)None
阅读全文
0 0
- perl 和 python中的回调函数
- Perl 回调函数和闭包
- perl 回调函数
- perl 回调函数
- perl 回调函数
- python中的回调函数
- Perl 回调函数例子
- python中的回调函数例子
- java和javascript中的回调函数
- ruby和rails中的回调函数
- C++和C#中的回调函数
- Android和Java中的回调函数
- js和jquery中的回调函数
- PYTHON 回调函数
- Python 回调函数
- PYTHON 回调函数
- python--回调函数
- python 回调函数
- JZOJ 5456. 【NOIP2017提高A组冲刺11.6】奇怪的队列
- RAID技术详解
- 线性基
- Source Insight基本教程
- sendmail demo
- perl 和 python中的回调函数
- jQuery的初始加载函数和html事件加载顺序
- Python 3.6 Json 序列化
- python3环境下的pandas,其max方法有一个大坑
- 【Oracle】重命名表空间
- paperweekly
- 由mp3音频录制 初探NDK编程
- lavarel 响应宏
- Android Eclipse实现Google Pay内支付