__init__.py 文件源码

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

项目:filibuster 作者: LettError 项目源码 文件源码
def content():
    """Return one dictionary that contains all dictionaries of the
    module. By making a function rather than part of the namespace,
    the content can be updated dynamically. Should not make any
    difference in speed for normal use."""

    global _contentCache

    if _contentCache is not None:
        return _contentCache

    # import each time by looking at the files
    mods = glob.glob1(__path__[0], '*.py')
    _contentCache = content = {}

    for m in mods:
        if m[:2] == '__':
            continue
        modname = __name__ + '.' + m[:-3]
        path = string.split(modname, '.')
        module = __import__(modname)
        # find the deepest submodule
        for modname in path[1:]:
            module = getattr(module, modname)
        if hasattr(module, 'content'):
            content.update(module.content)
            continue
        else:
            if DEBUG:
                print __name__, 'submodule ', module, 'misses a content dictionary.'
    return content
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号