newbie : prune os.walk

Tim Roberts timr at
Sat Mar 12 07:44:52 CET 2005

Rory Campbell-Lange <rory at> 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 actually change the list that was passed in.  It creates a NEW
empty list and binds it to "dir".

If you want to empty the "dir" variable, try:
    del dir[:]
- Tim Roberts, timr at
  Providenza & Boekelheide, Inc.

More information about the Python-list mailing list