Rory Campbell-Lange <[EMAIL PROTECTED]> wrote:
>
>Hi. How can I list root and only one level down? I've tried setting dirs
>= [] if root != start root, but it doesn't work. I clearly don't
>understand how the function works. I'd be grateful for some pointers.
The statement
dir = []
does not ac
Rory Campbell-Lange wrote:
Hi. How can I list root and only one level down? I've tried setting dirs
= [] if root != start root, but it doesn't work. I clearly don't
understand how the function works. I'd be grateful for some pointers.
base = '/tmp/test'
for root, dirs, files in os.walk(base
Rory Campbell-Lange wrote:
Hi. How can I list root and only one level down? I've tried setting dirs
= [] if root != start root, but it doesn't work.
It sounds like you are trying to take advantage of the feature
described in the docs where "the caller can modify the dirnames
list in-place (perhaps
Untestet:
def foo(base, depth=2):
for root, dirs, files in os.walk(base, True):
if len(root.split(os.sep)) < depth:
yield root, dirs, files
for root, dirs, files in foo("/tmp"):
print root, dirs, files
--
Regards,
Diez B. Roggisch
--
http://mail.python.org/ma