Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Class member become static
#1
In the following code data must be an non static attribute of the class Node:

class Node:
    total = 0
    def __init__(self,parent,data):
        Node.total=Node.total+1
        self.index=Node.total
        self.data = data
        if self.index!=1:
            self.parent = parent.index
            self.depth=parent.depth+1
        else:
            self.parent=1
            self.depth=0

list=[Node(0,[2,2,2,2,2,2])]
i=0
while list[i].depth<2:
    for j in range(0,6):
        p_data=list[i].data
        num=p_data[j]
        if num!=0:           
            p_data[j]=0
            for k in range(1,num+1):
                p_data[(j+k)%6]=p_data[(j+k)%6]+1
            list.append(Node(list[i],p_data))
    i=i+1
       
For every class instance in list all member have the same value for member data and also become static.
Reply


Messages In This Thread
Class member become static - by Quasar999 - Sep-14-2023, 10:17 PM
RE: Class member become static - by deanhystad - Sep-16-2023, 12:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem usage of static method akbarza 5 594 Feb-03-2024, 07:43 AM
Last Post: paul18fr
  Static type checking with PyPy pitosalas 1 502 Dec-14-2023, 09:29 PM
Last Post: deanhystad
  can Inner Class reference the Outer Class's static variable? raykuan 6 6,040 Jul-01-2022, 06:34 AM
Last Post: SharonDutton
  labels.append(self.classes.index(member.find('name').text)) hobbyist 1 1,963 Dec-15-2021, 01:53 PM
Last Post: deanhystad
Photo Output Static image on HDMI2 random816382 0 1,424 Oct-18-2021, 11:21 AM
Last Post: random816382
  How to define a variable in Python that points to or is a reference to a list member JeffDelmas 4 2,717 Feb-28-2021, 10:38 PM
Last Post: JeffDelmas
  Syntax to print ndarray member of class containing ndarray pjfarley3 6 3,300 Jul-09-2020, 06:29 AM
Last Post: pjfarley3
  Instance of 'socket' has no 'error' member fedex03 1 2,929 May-13-2020, 03:23 PM
Last Post: deanhystad
  Are there optimizer for static code? AlekseyPython 5 2,618 Nov-03-2019, 07:52 AM
Last Post: AlekseyPython
  How I can recognize that member is classmethod of staticmethod? AlekseyPython 0 1,863 Feb-17-2019, 07:01 AM
Last Post: AlekseyPython

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020