logo

... pathlib: pathlib



Notes

Let's compare the two styles.

os.path style

import os 
import json

path_str = os.path.join("settings", "config.json")
with open(path_str) as f:
    d = json.loads(f.read())

pathlib style

import json
import pathlib

p = pathlib.Path("settings", "config.json")
d = json.loads(p.read_text())

It may certainly be a matter of preference, but the fact that one does not need the context manager with open() is appreciated.

Feedback? See an issue? Something unclear? Feel free to mention it here.



If you want to be kept up to date, consider signing up for the newsletter.