The fts interface from BSD is simpler to use than Python's os.walk for most cases. It's also more flexible, it provides more information, and it requires far fewer calls to stat, making it inherently faster (around 3x-7x on tests on different platforms) for many use cases.

Interface

The fts module's interface is a Pythonified version of the BSD (and probably future POSIX) fts API.

Changes from the BSD interface are:

fts.open in place of fts_open. Constants, functions, and struct members lose the FTS_ and fts_ prefixes. Failures raise OSError. (Error reading directories, etc., are generally not failures, and are returned in the error field of an FTSENT.) All other functions become methods of the FTS object (e.g., f.read() instead of fts_read(f)).

Never mind…

As pointed out by Nick Coghlan, a generator expression translates the argument of the outermost for clause into the argument to the generator function, not a local within the generator function.
Blog Archive
About Me
About Me
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.