This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Syntax error in Python Library Reference, 6.1.4. Files ...
Type: Stage:
Components: Documentation Versions: Python 2.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, schliep
Priority: normal Keywords:

Created on 2005-09-27 16:56 by schliep, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg26402 - (view) Author: Alexander Schliep (schliep) Date: 2005-09-27 16:56
See http://docs.python.org/lib/os-file-dir.html 
Python Library Reference, first example in Section
6.1.4 Files and Directories has an obvious syntax error.

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),  #error
    print "bytes in", len(files), "non-directory files"
    if 'CVS' in dirs:
        dirs.remove('CVS')  # don't visit CVS directories


Should be     
    print sum([getsize(join(root, name)) for name in
files]),   
msg26403 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-09-27 17:46
Logged In: YES 
user_id=1188172

No, sorry. The docs you are referring to are the docs for
Python 2.4, and Python 2.4 introduces so-called "generator
expressions", and this is one.

See http://docs.python.org/whatsnew/node4.html for more
information.
History
Date User Action Args
2022-04-11 14:56:13adminsetgithub: 42419
2005-09-27 16:56:47schliepcreate