[Tutor] getting around ValueError in os.walk

Andrew D. Fant fant at pobox.com
Mon Jan 30 21:16:52 CET 2006


I'm working on a program to do some processing on a directory tree. If I had
been doing it in a shell script, the core of the processing would have been in
a "find $ROOT -type f -name FOO -print" command"

On the web, I found a snippet of code that demonstrated the os.walk module and
I created a simple test program to work on my tree that looked like this:

#!/usr/bin/python
import os

for (dirpath. subdirs, filenames) in os.walk("/foo/bar"):
        for file in filenames:
                if file.endswith(".baz"):
                        print os.path.join(dirpath,f)


when I try to run it, I get a "ValueError: too many values to unpack" which I
think  comes from the fact that there is a subdirectory of /foo/bar which has
over 2500 files in it.  The tree can't be easily restructured for legacy
reasons.  Can anyone suggest the best way to get around this in code?

Thanks,
	Andy

-- 
Andrew Fant    | And when the night is cloudy    | This space to let
Molecular Geek | There is still a light          |----------------------
fant at pobox.com | That shines on me               | Disclaimer:  I don't
Boston, MA     | Shine until tomorrow, Let it be | even speak for myself



More information about the Tutor mailing list