Skip to content
UPEEC

pathlib

Object-oriented file paths that work on every operating system.

Beginner
Comments 0
from pathlib import Path
data = Path.home() / "projects" / "logs"
data.mkdir(parents=True, exist_ok=True)
for p in data.glob("*.csv"):
    print(p.name, p.stat().st_size)
text = (data / "readme.txt").read_text(encoding="utf-8")

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.