[Python-Dev] Issue 11406: adding os.scandir(), a directory iterator returning stat-like info (original) (raw)

Ben Hoyt benhoyt at gmail.com
Sat May 11 03:29:00 CEST 2013


In the python-ideas list there's a thread "PEP: Extended statresult" about adding methods to statresult.

Using that, you wouldn't necessarily have to look at st.stmode. The method could perform an additional os.stat() if the field was None. For example: # Build lists of files and directories in path files = [] dirs = [] for name, st in os.scandir(path): if st.isdir(): dirs.append(name) else: files.append(name)

That's not too bad. However, the st.is_dir() function could potentially call os.stat(), so you'd have to be specific about how errors are handled. Also, I'm not too enthusiastic about how much "API weight" this would add -- do you need st.is_link() and st.size() and st.everything_else() as well?

-Ben



More information about the Python-Dev mailing list