Python 双端队列追加问题

Python deque append issue

我正在尝试将 2 个项目插入双端队列,每个项目将有 2 个点。 Totally deque应该包含4个点。但它似乎是8分。 有人,请帮助我避免将这些重复点存储在项目队列中。 下面是代码。

from collections import deque

class Data:
    Points = list()
    
class Point:
    Tag = ""
    
queue = deque()

item1 = Data()
item2 = Data()

point1 = Point()
point2 = Point()
point3 = Point()
point4 = Point()

point1.Tag = "point1"
point2.Tag = "point2"
point3.Tag = "point3"
point4.Tag = "point4"

item1.Points.append(point1)
item1.Points.append(point2)
item2.Points.append(point3)
item2.Points.append(point4)

queue.append(item1)
queue.append(item2)

for it in queue:
    for p in it.Points:
        print(p.Tag)
class Data:
    Points = list()

这里,Points是实例间共享的class属性!但是您希望它成为一个 实例属性 :

class Data:
    def __init__(self):
        self.Points = list()
        # self.Points = []