def walk_level(path, level=<NUM_LIT:1>):
if level is None:<EOL><INDENT>level = float('<STR_LIT>')<EOL><DEDENT>path = expand_path(path)<EOL>if os.path.isdir(path):<EOL><INDENT>root_level = path.count(os.path.sep)<EOL>for root, dirs, files in os.walk(path):<EOL><INDENT>yield root, dirs, files<EOL>if root.count(os.path.sep) >= root_level + level:<EOL><INDENT>del dirs[:]<EOL><DEDENT><DEDENT><DEDENT>elif os.path.isfile(path):<EOL><INDENT>yield os.path.dirname(path), [], [os.path.basename(path)]<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>".format(repr(path)))<EOL><DEDENT>
Like os.walk, but takes `level` kwarg that indicates how deep the recursion will go.

    Notes:
        TODO: refactor `level`->`depth`

    References:
        http://stackoverflow.com/a/234329/623735

    Args:
        path (str):  Root path to begin file tree traversal (walk)
            level (int, optional): Depth of file tree to halt recursion at.
            None = full recursion to as deep as it goes
            0 = nonrecursive, just provide a list of files at the root level of the tree
            1 = one level of depth deeper in the tree

    Examples:
        >>> root = os.path.dirname(__file__)
        >>> all((os.path.join(base,d).count('/') == (root.count('/')+1))
        ...     for (base, dirs, files) in walk_level(root, level=0) for d in dirs)
        True