Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
dictionary containing instances of classes behaving oddly
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Erik Johnson, post: 2051554"] Similar to the example I gave, the lists my_list and mops shown above are executed just once: when your class definition is first parsed. The statement: def __init__(self,mops): is also executed just once, and the value for mops at that time is the value assigned to object attributes during object construction - a reference to record.mops, in your case. So, there are really only two lists here, class attributes record.my_list and record.mops. Each of your constructed objects is assigned a reference to record.mops. They all share that list. If you want a record object to have it's own list, give it a new, empty one and then populate it appropriately. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
dictionary containing instances of classes behaving oddly
Top