config.py 文件源码

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

项目:flask 作者: bobohope 项目源码 文件源码
def _parse_attr(cls, value):
        """Represents value as a module attribute.

        Examples:
            attr: package.attr
            attr: package.module.attr

        :param str value:
        :rtype: str
        """
        attr_directive = 'attr:'
        if not value.startswith(attr_directive):
            return value

        attrs_path = value.replace(attr_directive, '').strip().split('.')
        attr_name = attrs_path.pop()

        module_name = '.'.join(attrs_path)
        module_name = module_name or '__init__'

        sys.path.insert(0, os.getcwd())
        try:
            module = import_module(module_name)
            value = getattr(module, attr_name)

        finally:
            sys.path = sys.path[1:]

        return value
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号