Skip to content

Instantly share code, notes, and snippets.

@borntyping
Created June 28, 2018 15:03
Show Gist options
  • Save borntyping/a219c002cc5b805d13ecd6bb496916c4 to your computer and use it in GitHub Desktop.
Save borntyping/a219c002cc5b805d13ecd6bb496916c4 to your computer and use it in GitHub Desktop.
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