I create a function dynamically this way:
def create_function(value):
def _function():
print value
return _function
f1 = create_func(1)
f1()
which works fine and prints '1'.
but my problem is slightly different, say there is a variable called no_of_arguments which contains the number of arguments the function that is being returned (_function() ) takes.
def create_function():
no_of_arguments = int(raw_input()) #provided by user
def _function(a,b,c,....):
'this function has to accept a certain number of arguments, specified in the variable no_of_arguments'
#do something here
return _function
f1 = create_func()
f1(a,b,c......)
*argsand**kwargskeywords for functions with arbitrary parameters in Python. May be they will be helpfull.