SHARE
TWEET

to_json, from_json

DeaD_EyE Oct 22nd, 2018 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top