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: 2051551"] Ah - ok. In fact I simply had: class record: my_list =[] mops=[] def __init__(self,mops): self.mops=mops Where mops is something I pass in when i create the instance. I had thought that then each time I created an instance of the record class as an element of my dictionary: self.mop_list[record_number]=record(self.mops[:]) I would create a brand new instance of the record class.It would have a mops list initialized with mops (because the def__init__ constructor is called when the class is instantiated), and an empty, individual list my_list. I could then access each individual list by doing: self.mop_list[x].my_list[y]=something But in fact the same my_list is being accessed for all values of x, so a change to one list is in fact a change to them all. I think you might be right, but can't quite work it out myself! I'll keep trying :-) Thanks for your help, Ben [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
dictionary containing instances of classes behaving oddly
Top