python 回调函数
来源:互联网 发布:声音剪辑软件 编辑:程序博客网 时间:2024/05/29 11:13
def 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 + yapply_async(add, (2, 3), callback=print_result)C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/cookbook/a22.py('Got:', 5)# !/usr/bin/env python# -*- coding: utf-8 -*-def 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 + yapply_async(add, (2, 3), callback=print_result)class ResultHandler: def __init__(self): self.sequence = 0 def handler(self, result): self.sequence += 1 print ('[{}] Got: {}'.format(self.sequence, result))##实例化对象r = ResultHandler()##r.handler 调用对象方法apply_async(add, (2, 3), r.handler)C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/cookbook/a22.py('Got:', 5)[1] Got: 5
阅读全文
0 0
- PYTHON 回调函数
- Python 回调函数
- PYTHON 回调函数
- python--回调函数
- python 回调函数
- python中的回调函数
- python的回调函数
- callback回调函数--python
- python之回调函数
- callback回调函数 python
- python异步回调函数的实现
- python中的回调函数例子
- python回调函数用法实例分析
- python回调函数的使用方法
- python atexit 模块(回调函数)
- python sys.exitfunc (回调函数)
- python回调函数与eval函数
- python 构建一个回调函数
- Jave基础知识
- 有关结构体指针与函数传参返回值类型的六种方法
- 软件工程师成长为架构师必备的十项技能
- 初识实时流处理
- Mybatis plus like查询问题
- python 回调函数
- Mybatis 使用动态语句实现批量删除(delete结合foreach)
- 关于js动态渲染的元素绑定事件遇到的坑
- poj1129——Channel Allocation
- Kruskal模板 最小生成树
- 用户输入日、月和年(月份可以是月份号、月份名或月份缩写),程序返回一年中到给定日子(包括这一天)的总天数
- 如何成为一个架构师
- 图形学opengl实验一-渐变色六芒星
- springboot 集成pagehelper