Re: Need help with simple OOP Python question

2011-09-08 Thread Piet van Oostrum
Terry Reedy writes: > Indexing objects by their internal id is usually useless. obj.id is not the internal id. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help with simple OOP Python question

2011-09-05 Thread Terry Reedy
On 9/5/2011 9:15 AM, Kristofer Tengström wrote: Thanks everyone, moving the declaration to the class's __init__ method did the trick. Now there's just one little problem left. I'm trying to create a list that holds the parents for each instance in the hierarchy. This is what my code looks like no

Re: Need help with simple OOP Python question

2011-09-05 Thread Peter Otten
Jon Clements wrote: > I > must say I'm not 100% sure what the OP wants to achieve... Learn Python? ;) -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help with simple OOP Python question

2011-09-05 Thread Jon Clements
On Sep 5, 3:43 pm, Peter Otten <__pete...@web.de> wrote: > Kristofer Tengström wrote: > > Thanks everyone, moving the declaration to the class's __init__ method > > did the trick. Now there's just one little problem left. I'm trying to > > create a list that holds the parents for each instance in t

Re: Need help with simple OOP Python question

2011-09-05 Thread Kristofer Tengström
Thanks everyone, moving the declaration to the class's __init__ method did the trick. Now there's just one little problem left. I'm trying to create a list that holds the parents for each instance in the hierarchy. This is what my code looks like now: - cla

Re: Need help with simple OOP Python question

2011-09-05 Thread Peter Otten
Kristofer Tengström wrote: > Thanks everyone, moving the declaration to the class's __init__ method > did the trick. Now there's just one little problem left. I'm trying to > create a list that holds the parents for each instance in the > hierarchy. This is what my code looks like now: > > --

Re: Need help with simple OOP Python question

2011-09-05 Thread srinivas hn
Hi, You are getting same object because you are overriding the dictionary update. Its printing the proper value with the last updated instance of B. If you want to see the two different instances of class B give print self.sub inside the sub_add method in class A. CHEERS CNA 9986229891 On Mon,

Re: Need help with simple OOP Python question

2011-09-05 Thread Ben Finney
Kristofer Tengström writes: > Hi, I'm having trouble creating objects that in turn can have custom > objects as variables. That terminology is rather confused. I think what you want is to have instances with their own attributes. > class A: > sub = dict() This binds a single object (a new

Re: Need help with simple OOP Python question

2011-09-05 Thread Peter Otten
Kristofer Tengström wrote: > Hi, I'm having trouble creating objects that in turn can have custom > objects as variables. The code looks like this: > > - > > class A: > sub = dict() Putting it into the class like this means sub is shared by all in

Re: Need help with simple OOP Python question

2011-09-05 Thread Stephen Hansen
On 9/4/11 11:47 PM, Kristofer Tengström wrote: > Hi, I'm having trouble creating objects that in turn can have custom > objects as variables. The code looks like this: > > - > > class A: > sub = dict() You are sharing this single "sub" dictionary w