So I have a list of objects in which I have a list. The list has common strings and is supposed to have some specific strings for every object depending on another variable.
class test:
strings = []
name = None
Then I'm creating a list of objects
objects = []
i = 0
while i < 2 :
o = test()
o.name = "Object " + str(i)
objects.append(o)
i += 1
Then I'm adding general strings for both objects in the list
test.strings.append("String 1")
test.strings.append("String 1")
What I need is for each object to have a specific string after those, so I tried
test.append("testing")
for element in objects :
print element.strings[ len(element.strings) - 1 ]
element.strings[ len(element.strings) - 1 ] = element.name
print element.strings[ len(element.strings) - 1 ]
The output I'm getting is
testing
Object 0
Object 0
Object 1
And when I try to access element.strings where that string is it always is the last modification.
I tried appending individually, also, instead of doing the test.append before the for, but it added elements to every object. Is there a way to do what I'm trying to do?
Edit against duplicate: What the other question is asking is how to have independent data with no shared information. What I want is shared information with a few instances of specific data.