Skip to content

Instantly share code, notes, and snippets.

@tkutcher
Created February 19, 2022 17:45
Show Gist options
  • Save tkutcher/bf199cbd649ce455ab87870e2d6d6d1c to your computer and use it in GitHub Desktop.
Save tkutcher/bf199cbd649ce455ab87870e2d6d6d1c to your computer and use it in GitHub Desktop.
File IO Demo 1
@dataclasses.dataclass
class MyConfig:
x: str
y: str
def read_from_file() -> MyConfig:
with open("my-config.json", "r") as f:
d = json.load(f)
return MyConfig(d["x"], d["y"])
def write_to_file(c: MyConfig) -> None:
with open("my-config.json", "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