下面这个例子用可变长参数调用func并将可变长参数*arg传递给func。比如test(sleep, 1)就相当于 sleep(1);test(max, 1, -1)就相当于调用max(1,-1)。
def test(func, *args, **kargs):
if not callable(func):
raise RuntimeError, str(func) + ' not a callable object'
else:
func(*args, **kargs)
No comments:
Post a Comment