草庐IT

python - 使用字典选择要执行的函数

我正在尝试使用函数式编程来创建一个包含键和要执行的函数的字典:myDict={}myItems=("P1","P2","P3",...."Pn")defmyMain(key):defExecP1():passdefExecP2():passdefExecP3():pass...defExecPn():pass现在,我看到了用于在模块中查找已定义函数的代码,我需要执行以下操作:formyiteminmyItems:myDict[myitem]=???#todynamicallyfindthecorrespondingfunction所以我的问题是,如何列出所有Exec函数,然后使用字典将