This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xtreak
Recipients hmathers, xtreak
Date 2020-01-12.18:18:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1578853134.45.0.81485650783.issue39315@roundup.psfhosted.org>
In-reply-to
Content
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']
History
Date User Action Args
2020-01-12 18:18:54xtreaksetrecipients: + xtreak, hmathers
2020-01-12 18:18:54xtreaksetmessageid: <1578853134.45.0.81485650783.issue39315@roundup.psfhosted.org>
2020-01-12 18:18:54xtreaklinkissue39315 messages
2020-01-12 18:18:54xtreakcreate