一、mon.py:

class Mon:
    def __init__(self):
        pass

    def action(self, content):
        print('周一要{}'.format(content))

二、tue.py:

class Tue:
    def __init__(self):
        pass

    def action(self, action):
        print('周二要{}'.format(action))

三、wed.py:

class Wed:
    def __init__(self):
        pass

    def action(self, action):
        print('周三要{}'.format(action))

四、settings.py:

EX_FUNCS_LIST = [
    'ex_funcs.mon.Mon',
    'ex_funcs.tue.Tue',
    'ex_funcs.wed.Wed'
]

五、__init__.py:

import settings
import importlib


def cmd(content):
    for path_str in settings.EX_FUNCS_LIST:
        module_path, class_name = path_str.rsplit('.', maxsplit=1)
        module = importlib.import_module(module_path)
        cls = getattr(module, class_name)
        obj = cls()
        obj.action(content)

六、start.py:

import ex_funcs

if __name__ == '__main__':
    ex_funcs.cmd('工作')

 

posted on 2020-03-01 01:01  焚音留香  阅读(98)  评论(0编辑  收藏  举报