I've got a list of strings and I want to generate functions like this:
f_names = ["func1", "func2", "func3"] #and possibly many more
def generate_functions():
for funcname in f_names:
def <funcname value>(*args):
another_function(<funcname value>, *args)
Obviously I can't do that with code sample above.
What is the best way to accomplish my goal? Is it:
Generating temporary .py file with all
def
instructions and importing everything from it?Using
exec()
and generating def instructions in string?Using classes and
__call__()
?Using Python built-in tools? (If so what tools?)