def walk_up(start_dir, depth=<NUM_LIT:20>):
root = start_dir<EOL>for i in xrange(depth):<EOL><INDENT>contents = os.listdir(root)<EOL>subdirs, files = [], []<EOL>for f in contents:<EOL><INDENT>if os.path.isdir(os.path.join(root, f)):<EOL><INDENT>subdirs.append(f)<EOL><DEDENT>else:<EOL><INDENT>files.append(f)<EOL><DEDENT><DEDENT>yield root, subdirs, files<EOL>parent = os.path.dirname(root)<EOL>if parent and not parent == root:<EOL><INDENT>root = parent<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>
Walk up a directory tree