[蟒蛇菜谱]Python函数参数传递最佳实践
2014-08-27 15:40
357 查看
将函数作为参数传递,同时将该函数需要的参数一起传递。可参考threading.Timer的处理方式:
class threading.Timer(interval, function, args=[], kwargs={})
Create a timer that will run function with arguments args and keyword arguments kwargs, after interval seconds have passed.
内部实现中,调用function的方式:
初始化:
def __init__(self, interval, function, args=[], kwargs={}):
Thread.__init__(self)
self.function = function
self.args = args
self.kwargs = kwargs
调用:
self.function(*self.args, **self.kwargs)
使用方式:
t = Timer(1, foo, args=["hello"])
class threading.Timer(interval, function, args=[], kwargs={})
Create a timer that will run function with arguments args and keyword arguments kwargs, after interval seconds have passed.
内部实现中,调用function的方式:
初始化:
def __init__(self, interval, function, args=[], kwargs={}):
Thread.__init__(self)
self.function = function
self.args = args
self.kwargs = kwargs
调用:
self.function(*self.args, **self.kwargs)
使用方式:
t = Timer(1, foo, args=["hello"])
相关文章推荐
- [蟒蛇菜谱]Python日志记录最佳实践
- Python中函数参数的传递
- python 函数调用参数传递规则
- python 函数参数的传递说明
- python 函数参数的传递(参数带星号的说明) 元组传递 字典传递
- python 函数参数的传递
- python的函数参数传递
- Python中函数的参数传递
- Python的函数参数传递:传值?引用?
- Python的函数参数传递:传值?引用?
- Python的函数参数传递:传值?引用?
- 【转】python函数参数的传递
- Python的函数参数传递:传值?引用?
- python下函数参数的传递(参数带星号的说明)
- Ant:给Ant脚本传递参数的最佳实践
- [zt]Python的函数参数传递:传值?引用?
- python 函数参数的传递(参数带星号的说明)
- Python 函数参数的传递[转载]
- python中函数参数传递的几种方法
- python 函数参数的传递(参数带星号的说明)及调用