类转词典 转json 序列化 魔术方法

 

 

class Test:
def __init__(self, totals, uniques, pre):
self.totals = totals
self.uniques = uniques

self.cumulative_sum = totals
        if pre:
self.cumulative_sum +=pre.cumulative_sum
    
       



pre = Test(100, 200, None)
a = Test(1000, 2000, pre)
import json

d = [json.loads(json.dumps(i.__dict__)) for i in [pre, a]]

ddd = 9



posted @ 2024-05-23 18:38  papering  阅读(2)  评论(0编辑  收藏  举报