os.walk in python not running with cmd line parameter passed as path
Posted
by kartiku
on Stack Overflow
See other posts from Stack Overflow
or by kartiku
Published on 2010-05-21T08:37:18Z
Indexed on
2010/05/21
8:40 UTC
Read the original article
Hit count: 229
Hello, I needed to find the number of files in a folder on the system.
This is what i used:
file_count = sum((len(f) for _, _, f in os.walk('path')))
This works fine when we specify the path as a string in quotes, but when I enter a variable name that holds the path, type(file_count) is a generator object, and hence cannot be used as an integer.
How to solve this and why does this happen?
© Stack Overflow or respective owner