类转词典 转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 @   papering  阅读(3)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
历史上的今天:
2023-05-23 软件 授权 加密 加固
2022-05-23 Lock-free Observations for Prometheus Histograms
2022-05-23 RVA relative virtual address PE
2022-05-23 VMA anonymous virtual memory area 匿名虚拟内存区域
2019-05-23 redis incr incrby decr decrby命令 原理
2018-05-23 任何不看源码的代码引入都是存在定时爆炸的可能
2018-05-23 博客数计数
点击右上角即可分享
微信分享提示