os.walk in python not running with cmd line parameter passed as path
- by kartiku
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?