__init__.py 文件源码

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

项目:filibuster 作者: LettError 项目源码 文件源码
def index(tagname):
    """Return the name of the submodule that tagname is defined in,
    as well as a list of modules and keys in which this tagname is used."""
    mods = glob.glob1(__path__[0], '*.py')
    keys = []
    usedin = {}

    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'):
            c = module.content
            for k in c.keys():
                if k == tagname:
                    keys.append(m)
                for item in c[k]:
                    if string.find(item, tagname) !=  -1:
                        usedin[(m, k)] = 1
    return keys, usedin.keys()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号