On this page
article
Tip #22: Prefer pathlib over os.path for file paths
Python tip #22: Prefer pathlib over os.path for file paths.
Tip
Prefer pathlib over os.path for file paths
Why
Following this practice makes your Python code more readable, maintainable, and less error-prone.
Example
# Before (avoid)
# ... less idiomatic approach ...
# After (prefer)
# ... idiomatic Python 3.10+ approach ...