resources.py 文件源码

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

项目:nengo_spa 作者: nengo 项目源码 文件源码
def resource_walk(package_or_requirement, resource_name):
    """Generate the file names in a resource tree.

    Parameters
    ----------
    package_or_requirement : str or Requirement
        Package or requirement that contains the resource.
    resource_name : str
        Name of the resource.

    Returns
    -------
    tuple
        For each directory in the tree rooted at the given resoruce a 3-tuple
        ``(dirpath, dirnames, filenames)`` is returned. *dirpath* is a string,
        the path to the directory starting with *resource_name*. *dirnames* is
        a list of the names of subdirectories in *dirpath*. *filenames* is a
        list of names of non-directory files in *dirpath*.
    """
    queue = [resource_name]
    while len(queue) > 0:
        dirpath = queue.pop()
        dirnames = []
        filenames = []
        for name in resource_listdir(package_or_requirement, dirpath):
            fullpath = os.path.join(dirpath, name)
            if resource_isdir(package_or_requirement, fullpath):
                dirnames.append(name)
                queue.append(fullpath)
            else:
                filenames.append(name)
        yield dirpath, dirnames, filenames
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号