Created
February 19, 2022 17:45
-
-
Save tkutcher/bf199cbd649ce455ab87870e2d6d6d1c to your computer and use it in GitHub Desktop.
File IO Demo 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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