Skip to content

Instantly share code, notes, and snippets.

@tkutcher
Last active February 19, 2022 17:48
Show Gist options
  • Save tkutcher/f611e5ef61b2cc324076b54a6aeb6f07 to your computer and use it in GitHub Desktop.
Save tkutcher/f611e5ef61b2cc324076b54a6aeb6f07 to your computer and use it in GitHub Desktop.
Testing File IO demo 2
def read_from_file(src_path="my-config.json") -> MyConfig:
with open(src_path, "r") as f:
d = json.load(f)
return MyConfig(d["x"], d["y"])
def write_to_file(c: MyConfig, dest_path="my-config.json") -> None:
with open(dest_path, "w") as f:
f.write({"x": c.x, "y": c.y})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment