def lite(a,b,c):
#...
def big(func): # func = callable()
#...
#main
big(lite(1,2,3))
how to do this?
in what way to pass function with parameters to another function?
def lite(a,b,c):
#...
def big(func): # func = callable()
#...
#main
big(lite(1,2,3))
how to do this?
in what way to pass function with parameters to another function?
Why not do:
big(lite, (1, 2, 3))
?
Then you can do:
def big(func, args):
func(*args)
Not this way, you're passing to big the return value of lite() function.
You should do something like:
def lite(a, b, c):
return a + b + c
def big(func, arg):
print func(arg[0], arg[1], arg[2])
big(lite, (1, 2, 3))
Similar problem is usually solved in two ways:
See the example:
#!/usr/bin/python
def lite(a,b,c):
return "%r,%r,%r" % (a,b,c)
def big(func): # func = callable()
print func()
def big2(func): # func = callable with one argument
print func("anything")
def main():
param1 = 1
param2 = 2
param3 = 3
big2(lambda x: lite(param1, param2, param3))
def lite_with_params():
return lite(param1,param2,param3)
big(lite_with_params)
main()