__init__.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:pelisalacarta-ce 作者: pelisalacarta-ce 项目源码 文件源码
def load_controllers():
    controllers=[]
    path=os.path.split(__file__)[0]
    for fname in os.listdir(path):
        mod,ext=os.path.splitext(fname)
        fname=os.path.join(path,fname)
        if os.path.isfile(fname) and ext=='.py' and not mod.startswith('_'):
            try:
              exec "import "+ mod + " as controller"
            except:
              import traceback
              logger.error(traceback.format_exc())

            for c in dir(controller):
                cls=getattr(controller, c);

                if not c.startswith('_') and isclass(cls) and issubclass(cls, Controller) and Controller != cls:
                    controllers.append(cls)
    return controllers
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号