Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Class member become static
#2
Do not use "list" as a variable name. list() is a built-in function that creates a list.

There are no "static" variables in Python. "total" is a class variable.

Your problem is here:
        p_data=list[i].data
p_data and list[1].data are the same list object. Even though "data" is an instance variable that references a list, all instances of Node end up referencing the same list object. Do you want each node to have their own list? You could do this:
        p_data=list[i].data.copy()
Now p_data and list[1].data are different lists. They have the same contents, but they are different list objects. When you create a new Node using pdata, the data in the old Node and the new Node will be different lists.
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 616 Feb-03-2024, 07:43 AM
Last Post: paul18fr
  Static type checking with PyPy pitosalas 1 511 Dec-14-2023, 09:29 PM
Last Post: deanhystad
  can Inner Class reference the Outer Class's static variable? raykuan 6 6,104 Jul-01-2022, 06:34 AM
Last Post: SharonDutton
  labels.append(self.classes.index(member.find('name').text)) hobbyist 1 1,978 Dec-15-2021, 01:53 PM
Last Post: deanhystad
Photo Output Static image on HDMI2 random816382 0 1,437 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,734 Feb-28-2021, 10:38 PM
Last Post: JeffDelmas
  Syntax to print ndarray member of class containing ndarray pjfarley3 6 3,331 Jul-09-2020, 06:29 AM
Last Post: pjfarley3
  Instance of 'socket' has no 'error' member fedex03 1 2,944 May-13-2020, 03:23 PM
Last Post: deanhystad
  Are there optimizer for static code? AlekseyPython 5 2,664 Nov-03-2019, 07:52 AM
Last Post: AlekseyPython
  How I can recognize that member is classmethod of staticmethod? AlekseyPython 0 1,874 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