Python 允许你实时地创建函数参数列表. 只要把所有的参数放入一个元组中,然后通过内建的 apply函数调用函数.
#!/usr/bin/python def test(a, b) : print a, b apply(test, ('hello', 'world')) apply(test, (1, 2 + 3)) r = apply(lambda x, y : x + y, (1, 2)) print r apply(test, (), {'a' : 'avalue', 'b' : 'bvalue'}) #apply(test, {'a' : 'avalue', 'b' : 'bvalue'}) #apply(test, {'name' : 'fisher', 'sex' : 'm'})
被注释掉的两个不正确,参数必须是元祖,哪怕是空元祖,而且键值必须与函数的参数名称一致。如上例中,字典的键名称必须与test的参数名称一致。