49. Pathlib for File Handling
pathlib provides an object-oriented approach to file paths.
Example
from pathlib import Path
p = Path("example.txt")
p.write_text("Hello")
print(p.read_text())
Benefits
- Cleaner than using
os.path - Cross-platform compatibility
Wrap-Up
Prefer pathlib for working with filesystem paths.