Advertisement
DeaD_EyE

to_json, from_json

Oct 22nd, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.27 KB | None | 0 0
  1. class Foo:
  2.     def __init__(self, a, b, c):
  3.         self.a, self.b, self.c = a, b, c
  4.  
  5.     def to_json(self):
  6.         return json.dumps({'a': self.a, 'b': self.b, 'c': self.c})
  7.  
  8.     @classmethod
  9.     def from_json(cls, content):
  10.         return cls(**json.loads(content))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement