類轉詞典 轉json 序列化 魔術方法

papering發表於2024-05-23

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



相關文章