setup_helper.py 文件源码

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

项目:tredparse 作者: humanlongevity 项目源码 文件源码
def get_init(self, filename="__init__.py"):
        """ Get various info from the package without importing them
        """
        import ast

        with open(filename) as init_file:
            module = ast.parse(init_file.read())

        itr = lambda x: (ast.literal_eval(node.value) for node in ast.walk(module) \
            if isinstance(node, ast.Assign) and node.targets[0].id == x)

        try:
            return next(itr("__author__")), \
                   next(itr("__email__")), \
                   next(itr("__license__")), \
                   next(itr("__version__"))
        except StopIteration:
            raise ValueError("One of author, email, license, or version"
                        " cannot be found in {}".format(filename))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号