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.


Episode Notes

To load in the file into a dictionary we run;

import json
import pathlib

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

We can move the file to a new location by running;

path_to = pathlib.Path("data", "configuration.json")
p.rename(path_to)

Alternatively, you can also copy the file by taking the dictionary that we read in and writing that text somewhere.

text = json.dumps(d)
pathlib.Path("data", "config-1.json").write_text(text)

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

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