pathlib logo pathlib: making files

1 2 3 4 5 6 7

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")

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)