logo

... pathlib.


The goal of this series of videos is to demonstrate how to deal with files, paths and folders from python programmatically. We'll mainly discuss the python pathlib module.


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 getting the newsletter.