Python·100 questions

How to safely work with paths (pathlib)?

Answer
from pathlib import Path.
p = Path('data') / 'file.txt'.
p.exists(), p.is_file(), p.read_text(encoding='utf-8').
Create folder: p.parent.mkdir(parents=True, exist_ok=True).
Cross-platform and readable.
Was this answer helpful?

More questions in this topic

Related questions from other topics