How to fix this error in the example in 6.1.4 Files and Directories

Fredrik Lundh fredrik at pythonware.com
Fri Apr 15 13:07:31 EDT 2005


<jarrod.roberson at gmail.com> wrote:

> the following code is from the Python 2.3.5 docs (
> http://www.python.org/doc/2.3.5/lib/os-file-dir.html )
>
> import os
> from os.path import join, getsize
> for root, dirs, files in os.walk('python/Lib/email'):
>    print root, "consumes",
>    print sum([getsize(join(root, name)) for name in files]),
>    print "bytes in", len(files), "non-directory files"
>    if 'CVS' in dirs:
>        dirs.remove('CVS')  # don't visit CVS directories
>
> every time I try and run it I get the following error
>
>    print sum([getsize(join(root,name)) from name in files]),
>                                           ^

if you're using examples from the 2.3.5 documentation, maybe you
shouldn't run them under 1.5.2...

(the code you included runs just fine on Python 2.3 and 2.4 on my
machine.   under Python 2.0 and 2.1 and 2.2, it complains about a
missing "walk" function.  in Python 1.5.2, it gives a syntax error that
looks a lot like the one you included, except that you didn't include
the actual error message...)

</F> 






More information about the Python-list mailing list