def test(name):
print "name:", name
func = test
func("testing") # it works, as I know that the function test accepts one parameter.
我的问题是,如果“测试”具有不同数量的参数,具体取决于场景以及“func”如何知道要传递多少个参数以及这些参数名称是什么。
对不起,如果我不清楚。这将提供更清晰的场景图。
我有一个函数调度程序。
testcase_obj = testcase() # A object of a class
if command.startswith("test1"):
output = exec_test1()
elif command.startswith("do_test"):
output = exec_do_test(testcase_obj)
现在,每当用户在执行脚本时发送选项时,我想包装一个函数。我将上面的代码更改为:
testcase_obj = testcase() # A object of a class
if command.startswith("test1"):
func = exec_test1() # Mistake, this should be func = exec_test1
elif command.startswith("do_test"):
func = exec_do_test(testcase_obj) # I don't know how assign exec_do_test along
# with its parameter to 'func'. I don't want to
# to call exec_to_test.
if option_given:
func = wrapper_func(func)
output = func() # At this point I don't how many parameters that "func" takes.