1... 目的,一坨坨的函数选择执行...
2...code
# file m.py from obj.tsk import Task from obj.acc import Acc map_name_cls = {"task": Task, "acc": Acc} fconf = [ {"task_type": "task", "task_list": ["task", "pre_task", "lf"]}, {"task_type": "acc", "task_list": ["task", "pre_task", "lf"]} ] if __name__ == '__main__': for k in fconf: tsk_type = k["task_type"] tsk_list = k["task_list"] cls = map_name_cls[tsk_type](tsk_list) for ts in tsk_list: run_flag = True try: func = getattr(cls, ts) except: run_flag = False if run_flag: func()
___
# file obj/tsk.py class Task: def __init__(self, *args): pass @staticmethod def pre_task(): print("running task pre_task") @staticmethod def task(): print("running tsk task") @staticmethod def post_task(): print("running tsk post_task")
__
file obj/acc.py 和tsk.py类同
3... output