python类import_module()的实例源码

load_email_templates.py 文件源码 项目:plugs-mail 作者: solocompt 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_apps(self):
        """
        Get the list of installed apps
        and return the apps that have
        an emails module
        """
        templates = []
        for app in settings.INSTALLED_APPS:
            try:
                app = import_module(app + '.emails')
                templates += self.get_plugs_mail_classes(app)
            except ImportError:
                pass
        return templates
routing.py 文件源码 项目:stormtrooper 作者: CompileInc 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_channel_routings():
    channel_routing = []
    for app in settings.INSTALLED_APPS:
        try:
            routing = import_module("{}.routing".format(app))
            channel_routing.extend(routing.channel_routing)
        except:
            continue
    return channel_routing
utils.py 文件源码 项目:pinax-notifications-backends 作者: psychok7 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_class_from_path(path):
    # This function is helpful to avoid circular imports.
    module_name, class_name = path.rsplit(".", 1)
    class_ = getattr(import_module(module_name), class_name)
    return class_
apps.py 文件源码 项目:djangoevents 作者: ApplauseOSS 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def import_app_module(app_module_name, module_name):
    full_module_name = '%s.%s' % (app_module_name, module_name)
    try:
        import_module(full_module_name)
    except ImportError:
        # we need to re-raise exception in case there was import error inside
        # `module_name` module
        module_file_name = get_module_file_name(app_module_name, module_name)
        if os.path.exists(module_file_name):
            raise
apps.py 文件源码 项目:djangoevents 作者: ApplauseOSS 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_module_file_name(app_module_name, module_name):
    module = import_module(app_module_name)
    module_dir = os.path.dirname(module.__file__)
    return os.path.join(module_dir, '%s.py' % module_name)
autodiscover.py 文件源码 项目:django_mc 作者: team23 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def autodiscover():
    for app in settings.INSTALLED_APPS:
        mod = import_module(app)
        try:
            import_module('%s.%s' % (app, 'link_resolvers'))
        except:
            if module_has_submodule(mod, 'link_resolvers'):
                raise


问题


面经


文章

微信
公众号

扫码关注公众号