[ python-Bugs-1278906 ] invalid syntax in os.walk() first example
SourceForge.net
noreply at sourceforge.net
Thu Sep 1 14:44:57 CEST 2005
Bugs item #1278906, was opened at 2005-09-01 06:55
Message generated for change (Comment added) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1278906&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Documentation
Group: Python 2.5
>Status: Closed
>Resolution: Works For Me
Priority: 5
Submitted By: YoHell (yohell)
Assigned to: Nobody/Anonymous (nobody)
Summary: invalid syntax in os.walk() first example
Initial Comment:
Hi!
The first example code block in the documentation for
os.walk() has invalid syntax in it.
The docs are available here:
http://www.python.org/doc/current/lib/os-file-dir.html#l2h-1466
This is the example code block:
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
Line 5 has the the invalid syntax:
print sum(getsize(join(root, name)) for name in files),
The example works if brackets are added like so:
print sum([getsize(join(root, name)) for name in
files]),
I recommend that someone responsible should make this
update in the docs.
You guys are brilliant. Thanks for a splendid language
with docs to match!
Cheers!
/Joel Hedlund
PhD student,
IFM Bioinfomatics, Linköping University
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2005-09-01 07:44
Message:
Logged In: YES
user_id=80475
I suspect you are using Py2.4 documentation while running
Py2.3 or earlier. In Py2.4, the bracketless syntax was
introduced with new semantics which produce a similar result
but run with a generator instead of a list comprehension,
resulting in a significant savings in memory.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1278906&group_id=5470
More information about the Python-bugs-list
mailing list