core.py 文件源码

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

项目:deb-python-pecan 作者: openstack 项目源码 文件源码
def __translate_root__(self, item):
        '''
        Creates a root controller instance from a string root, e.g.,

        > __translate_root__("myproject.controllers.RootController")
        myproject.controllers.RootController()

        :param item: The string to the item
        '''

        if '.' in item:
            parts = item.split('.')
            name = '.'.join(parts[:-1])
            fromlist = parts[-1:]

            module = __import__(name, fromlist=fromlist)
            kallable = getattr(module, parts[-1])
            msg = "%s does not represent a callable class or function."
            if not six.callable(kallable):
                raise TypeError(msg % item)
            return kallable()

        raise ImportError('No item named %s' % item)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号