Modules - pathlib
introduced in Python 3.4, and it provides an object-oriented way to work with filesystem paths
High-level Path objects instead of string-based path manipulation
Cross-platform path handling (Windows vs Unix differences handled automatically)
Easy file operations: reading, writing, iterating, checking existence
Cleaner, more expressive code than os.path
from pathlib import Path
p = Path("data/example.txt")
# Check existence
print(p.exists())
# Read text
content = p.read_text()
# Write text
p.write_text("Hello, world!")
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext