Created
June 28, 2018 15:03
-
-
Save borntyping/a219c002cc5b805d13ecd6bb496916c4 to your computer and use it in GitHub Desktop.
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
import path | |
import json | |
import attr | |
import cattr | |
@attr.s() | |
class Config: | |
foo: int = attr.ib() | |
bar: str = attr.ib() | |
def load() -> Config: | |
return cattr.structure(json.loads(path.Path('config.json').read_text()), Config) | |
def save(config: Config): | |
path.Path('config.json').write_text(json.dumps(cattr.unstructure(config))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment