Working with File Paths using pathlib
Navigate and manipulate file paths with the modern pathlib module.
Introduction
pathlib provides an object-oriented interface to filesystem paths, replacing brittle os.path string manipulation.
Creating a Path
from pathlib import Path; p = Path('data/file.txt') creates a path object. Works on all platforms.
from pathlib import Path
p = Path('data/file.txt')
print(p)All lessons in this course
- Opening and Reading Files
- Writing and Appending to Files
- Using the with Statement for Files
- Working with File Paths using pathlib