Join Nostr
2026-04-10 18:10:04 UTC

Trey Hunner 🐍 on Nostr: Python Tip #100 (of 365): Prefer the pathlib.Path object's is_file() and is_dir() ...

Python Tip #100 (of 365):

Prefer the pathlib.Path object's is_file() and is_dir() methods over exists()

The exists method tells you SOMETHING is there but not WHAT.

Using is_file() or is_dir() is more explicit about what you're actually checking for, and usually what you actually want.

Usually when I find myself using exists(), I'll realize that I wanted one of the more specific methods instead.

#Python #DailyPythonTip