Data Classes
A lib for easier data class creation!
Serializing and Deserializing
dataclass.py:
import json
from dataclasses import dataclass, asdict
@dataclass
class Foo:
x: str
# Serializing
f = Foo("Hello, World!")
with open("foo.json", "w") as jsonfile:
json.dump(asdict(f), jsonfile, indent=2)
# Deserializing
with open("foo.json") as jsonfile:
f = Foo(**json.load(jsonfile))
foo.json:
{
"x": "Hello, World!"
}