__init__.py 文件源码

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

项目:sahriswiki 作者: prologic 项目源码 文件源码
def loadMacros():
    path = os.path.abspath(os.path.dirname(__file__))
    p = lambda x: os.path.splitext(x)[1] == ".py"
    modules = [x for x in os.listdir(path) if p(x) and not x == "__init__.py"]

    macros = {}

    for module in modules:
        name, _ = os.path.splitext(module)

        moduleName = "%s.%s" % (__package__, name)
        m = __import__(moduleName, globals(), locals(), __package__)

        p = lambda x: isfunction(x) and getmodule(x) is m
        for name, function in getmembers(m, p):
            name = name.replace("_", "-")
            try:
                macros[name] = function
            except Exception, e:
                continue

    return macros
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号