common.py 文件源码

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

项目:respeaker_virtualenv 作者: respeaker 项目源码 文件源码
def _find_files(root_dir, should_include):
    """
    Return a list of paths to all modules below the given directory.

    Arguments:

      should_include: a function that accepts a file path and returns True or False.

    """
    paths = []  # Return value.

    is_module = lambda path: path.endswith(".py")

    # os.walk() is new in Python 2.3
    #   http://docs.python.org/library/os.html#os.walk
    for dir_path, dir_names, file_names in os.walk(root_dir):
        new_paths = [os.path.join(dir_path, file_name) for file_name in file_names]
        new_paths = filter(is_module, new_paths)
        new_paths = filter(should_include, new_paths)
        paths.extend(new_paths)

    return paths
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号