Created
December 15, 2014 21:12
-
-
Save atiaxi/c3662f5947fa33cfff92 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 json | |
class Blarg: | |
def __init__(self, something=1): | |
self.something=something | |
self.werg = {"another thing": 1} | |
def to_json(self): | |
return json.dumps({ | |
"something": self.something, | |
"werg": self.werg, | |
}) | |
@classmethod | |
def from_json(cls, json_string): | |
json_dict = json.loads(json_string) | |
proto = cls(json_dict['something']) | |
proto.werg = json_dict['werg'] | |
return proto | |
b = Blarg("hi") | |
stored = b.to_json() | |
print stored | |
restored = Blarg.from_json(stored) | |
print restored.something | |
print restored.werg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment