Elegant Filesystem Interactions in Python using pathlib

By Johan Herland

Anyone who has written python code to manipulate files and directories, will be familiar with the os and os.path modules. Starting with Python v3.4, there’s a new kid on the block - pathlib - which provides a fresh interface to querying and manipulating the filesystem.

This short session will introduce pathlib, and demonstrate how it can be used to avoid littering your code with calls to os.path.* functions. We will go through examples of how rewriting code to use pathlib makes it shorter and more readable.

Finally, we will conclude with a look ahead, noting where pathlib still has some ways to go before it has become a fully integrated part of Python.