Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我的名单怎么了?_Python_List_Class - Fatal编程技术网

Python 我的名单怎么了?

Python 我的名单怎么了?,python,list,class,Python,List,Class,我有一节课 class Dot: def __init__(self, x, y): self.x=x self.y=y 我有一个班级 class Cluster: ic=0 List=[Dot] colour=0 def __init__(self, Dot): self.List[self.ic]=Dot self.ic=self.ic+1 def includeDot(self, Dot):

我有一节课

class Dot:   
  def __init__(self, x, y):
    self.x=x
    self.y=y
我有一个班级

class Cluster:
    ic=0
    List=[Dot]
    colour=0
    def __init__(self, Dot):
      self.List[self.ic]=Dot 
      self.ic=self.ic+1
    def includeDot(self, Dot):
      self.List[self.ic]=Dot 
      self.ic=self.ic+1   
其中包括点列表(列表)

我有ClusterMaker类,其中是集群列表(和一些其他过程,但这对于这个问题并不重要)

最后,我的表单上有一个按钮,它开始创建点和簇

def onChoose(self):            
       # ClMaker=ClusterMaker()   
       self.total=self.ent.get().strip() #how many dots we haver
       self.CM=ClusterMaker()
       i=0    
       while (i < int(self.total)):
          dot=Dot(randint(0, 575), randint(0,670))
          clst=Cluster(dot)
          clst.colour= randrange(100, 999, 15)  
          self.CM.addCluster(clst)
          box.showerror('j', str(str(self.CM.CList[i].List[0].x)+str(clst.List[0].x)))
          this box shows us x coord of every dot in our cluster list
          self.canvas.create_oval(clst.List[0].x, clst.List[0].y, clst.List[0].x+10, clst.List[0].y+10, fill=str("#"+str(clst.colour)))
          i=i+1 
       b=0
       while(b<6):
          box.showerror('j', str(self.CM.CList[b].List[0].x))
          and this box shows us x coords too
          b=b+1 
def onChoose(自):
#ClMaker=ClusterMaker()
self.total=self.ent.get().strip()#我们有多少个点
self.CM=ClusterMaker()
i=0
而(iwhile(b类属性实例化一次并在实例之间共享。您必须在
\uuuuu init\uuuu
中创建新列表:

def __init__(self, Dot):
    self.List = [Dot]
    self.List[self.ic]=Dot 
    self.ic=self.ic+1

ic
(在你的课堂上)和
self.ic
不是一回事,请不要给你的变量命名
List
。谢谢,我希望我能投票支持你)等我有了更多的声誉我会的。我只有11个,需要15个
def __init__(self, Dot):
    self.List = [Dot]
    self.List[self.ic]=Dot 
    self.ic=self.ic+1