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="Ben, post: 2051533"] Hello... I have a dictionary, where each value is a seperate instance of the same class: self.mop_list[record_number]=record(self.mops[:]) In my case I know that record_number takes the values 0,3,and 7 thanks to a loop, giving me three instances of the record class instantiaterd with some data I've pased in. The record object contains a list, and each element of that list should also contain an instance of a class should I append one to it: self.mop_list[record_number].my_list.append(my_class(0,0,0,self.mop_list[record_no].mops,0)) So within each record class I have access to any number of my_class instances, depending on how many times I have appended: self.mop_list[record_number].my_list[index] This seems to work without any errors. But bizzarely I find that whatever my record number, the instance of "my_class" is appended to every list. So in this case self.mop_list[0].my_list.append(my_class(Some data for the constructor)) I would expect to append an instance of my_class to self.mop_list[0].my_list But annoyingly self.mop_list[0].my_list self.mop_list[3].my_list self.mop_list[7].my_list all have an instance of my_class created and appended to them. This is really confusing and quite annoying - I don't know whether anyone out there can make head or tail of what I'm doing wrong? Cheers, Ben [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
dictionary containing instances of classes behaving oddly
Top