Existence of mutable named tuple in Python?

前端 未结 10 2175
旧巷少年郎
旧巷少年郎 2020-11-29 16:23

Can anyone amend namedtuple or provide an alternative class so that it works for mutable objects?

Primarily for readability, I would like something similar to namedt

10条回答
  •  臣服心动
    2020-11-29 16:54

    Provided performance is of little importance, one could use a silly hack like:

    from collection import namedtuple
    
    Point = namedtuple('Point', 'x y z')
    mutable_z = Point(1,2,[3])
    

提交回复
热议问题