Message359862
You are appending to the class attribute where both shelf[0] and shelf[1] refers to the same list as seen by output of id. You might want to create an instance variable and use it for mutating across different instances. This could help : https://docs.python.org/3/tutorial/classes.html#class-and-instance-variables
class Folder():
papers = []
def __init__(self):
self.papers_self = []
shelf = []
shelf.append(Folder)
shelf.append(Folder)
print(f"{id(shelf[0]) = }")
print(f"{id(shelf[1]) = }")
shelf = []
shelf.append(Folder())
shelf.append(Folder())
print(f"{id(shelf[0].papers_self) = }")
print(f"{id(shelf[1].papers_self) = }")
shelf[0].papers_self.append("one")
shelf[1].papers_self.append("two")
print(f"{shelf[0].papers_self = }")
print(f"{shelf[1].papers_self = }")
id(shelf[0]) = 140411765635376
id(shelf[1]) = 140411765635376
id(shelf[0].papers_self) = 140411720636864
id(shelf[1].papers_self) = 140411720668608
shelf[0].papers_self = ['one']
shelf[1].papers_self = ['two'] |
|
Date |
User |
Action |
Args |
2020-01-12 18:18:54 | xtreak | set | recipients:
+ xtreak, hmathers |
2020-01-12 18:18:54 | xtreak | set | messageid: <1578853134.45.0.81485650783.issue39315@roundup.psfhosted.org> |
2020-01-12 18:18:54 | xtreak | link | issue39315 messages |
2020-01-12 18:18:54 | xtreak | create | |
|