I would like to iterate on distinct functions. I have looked into itertools, and I haven't found anything relevant there. I am looking for something like this:
import mymod
import sys
mymodule= sys.module[__name__]
if __name__ == 'main':
function_list1=['mymod.f1','mymod.f1(keyword=True)','mymod.f2']
for func in function_list1:
try:
print(getattr(mymod,func)()) # problem: how do I call the keyword
except Exception, e:
print(e)
function_list2=['f1','f2']
for func in function_list2:
getattr(mymodule,func)()
I have edited the code, because I want to make explicit that I want to call a function from another module and the current module. And I may want to pass a keyword to the function
module mymod
is a collection of functions, it imports some external modules and some modules written by me and then it defines functions that use only local variables
import sys
def f1(keyword=False, keyword2='something', keyword3=0.5):
a = 2
return a