oribi.sh ~ >

Tag: Best-Practices

Choose Your Path: Python's pathlib vs os.path
reading time: 3 minutes

For years, Python developers used the os.path module for file system operations, working with paths as strings. Python 3.4 introduced pathlib, a modern object-oriented approach that makes path handling more intuitive and readable.

In this post, I’ll show you how pathlib improves upon traditional os.path patterns, helping you write cleaner path-handling code.

The Traditional Approach: os.path#

The os.path module represents paths as strings. While functional, this approach requires remembering various function names and often leads to verbose code:

> git log --oneline