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: 2051545"] Well, it's a little bit difficult, but I think I actually know what's going on. You probably need some code that looks something like this, to ensure each object has it's own, independent list: class record: def __init__(self, init_list=None): self.my_list = [] if init_list is not None: self.my_list.extend(init_list) Here's what I think you are doing, and below should make it clear why that doesn't work: class record: def __init__(self, init_list=[]): That list above, the default initializer is constructed just once (when the def statement executes)! .... def __init__(self, init_list=[]): .... self.my_list = init_list .... [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
dictionary containing instances of classes behaving oddly
Top