def test(name):
print "name:", name
func = test
func("testing") # it works, as I know that the function test accepts one parameter.
My question is, what if “test” has varying number of arguments depending on the scenario and how “func” knows how many number of arguments to pass and what are those arguments name.
Sorry, if I am not clear. This would give more clear picture on the scenario.
I have a function dispatcher.
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)
Now, I want to wrap a function whenever user sends an option while executing the script. I changed above code as:
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.
Try the
inspectmodulewill give: