Python Projects & Skills / Files and data
Lesson 13 of 28
Working with paths
pathlib makes file paths easy and works the same on Windows and Linux.
Key points
- Path('folder') / 'file.txt'
- .exists(), .read_text()
- .glob('*.py') finds files
from pathlib import Path
for p in Path(".").glob("*.py"):
print(p.name, p.stat().st_size)Quiz · +10 XP
Which module is the modern way to handle file paths?
Log in to save progress and earn XP.