dataclass

作者: hehehehe | 来源:发表于2024-02-18 10:58 被阅读0次

    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)
    
    
    
    

    相关文章

      网友评论

          本文标题:dataclass

          本文链接:https://www.haomeiwen.com/subject/gyzpadtx.html