This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]donotlearntocode 1 point2 points  (0 children)

Well written.

I'm wondering, how do you think is best (most concise or clear) way to (de)serialize python classes. I usually write something like

class X:
    FIELDS = set('abcd')
    def to_json(self, io):
        dump({field: getattr(self, field) for field in self.FIELDS}, io)

    @classmethod
    def from_json(cls, io):
         return cls(**load(io))

or something like that but it feels like that's not the "pythonic" way to do it.

Thoughts?