Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is happening to my lists?
    primarykey
    data
    text
    <p>I have class Dot</p> <pre><code>class Dot: def __init__(self, x, y): self.x=x self.y=y </code></pre> <p>I have class Cluster</p> <pre><code>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 </code></pre> <p>Which include list of dots(List).</p> <p>And I have class ClusterMaker where is list of clusters(and some other procedures, but this is not important for this question)</p> <pre><code>class ClusterMaker: total=0 i=0 CList=[Cluster] def addCluster(self,Cluster): self.CList.append(Cluster) </code></pre> <p>Finally, there is button on my form which starts creating dots and clusters</p> <pre><code>def onChoose(self): # ClMaker=ClusterMaker() self.total=self.ent.get().strip() #how many dots we haver self.CM=ClusterMaker() i=0 while (i &lt; 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&lt;6): box.showerror('j', str(self.CM.CList[b].List[0].x)) and this box shows us x coords too b=b+1 </code></pre> <p>But what is going on in my lists? Why when I ask to show x coords for the second time it show the same x coord for all dots in all clusters?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload