Skip to content

.tip

· one of the small things

pathlib, not os.path string surgery

You get joining with /, reading in one call, and a type that says "this is a path" instead of str.

from pathlib import Path
config = Path.home() / ".config" / "app" / "settings.toml"
text = config.read_text()
for f in Path("content/tips").glob("*.mdx"): ...

Every standard library function that takes a path accepts a Path, so there's no reason left to build paths by gluing strings together.

python