dataclass

2024-02-18  本文已影响0人  hehehehe

https://mp.weixin.qq.com/s?__biz=MzU1Mjc3MzczMQ==&mid=2247490331&idx=1&sn=e85b1a836faa51b7e987bdd1e37341b8&chksm=fbfdaa17cc8a23016074bd67b0e640ba4f45858ab90b0325d1d711a0cb2145c1d485af45a8f7&scene=21#wechat_redirect

https://docs.python.org/3.12/library/dataclasses.html

https://www.attrs.org/en/stable/examples.html

from dataclasses import dataclass


@dataclass(order=True)
class A(object):
    name: str
    age: int

    # def __init__(self):
    #     print(234)
    def __post_init__(self):
        print(234)


a = A("2", 2)
a2 = A(name="2", age=2)
print(a.name, a2.age)
print(a == a2)


上一篇下一篇

猜你喜欢

热点阅读