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

fuzzylollipop jarrod.roberson at gmail.com
Fri Apr 15 12:52:12 EDT 2005


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]),
                                           ^

the only change I made was the path supplied to os.walk()
I think this has to do something with the list comprehension syntax
and I am trying to learn that part, using this example which seems to
be broken.




More information about the Python-list mailing list