Skip to Content
Modern Python Standard Library Cookbook
book

Modern Python Standard Library Cookbook

by Alessandro Molina
August 2018
Intermediate to advanced
366 pages
10h 14m
English
Packt Publishing
Content preview from Modern Python Standard Library Cookbook

How it works...

The os.walk function navigates the directory and all its subfolders. For each directory that it finds, it returns three values: the directory itself, the subdirectories it contains, and the files it contains. Then, it will move into the subdirectories of the directory it just provided and return the same three values for the subdirectory.

This means that in our recipe, basepath is always the current directory that is being inspected, directories are its subdirectories, and files are the files that it contains.

By iterating over the list of files contained within the current directory and joining their names with the directory path itself, we can get the path of all files contained in the directory. As os.walk will then move ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Python Development: Using Powerful Language Features in Real-World Applications

Advanced Python Development: Using Powerful Language Features in Real-World Applications

Matthew Wilkes

Publisher Resources

ISBN: 9781788830829Supplemental Content