Hello,
I have a class which contains a list:
this class is contained within another class, so that when the program is initially run, it builds the class object, and also a list of Monkey class objects, i.e.:
Now my problems comes when I try to run something like this:
because whatever number I put in the index of monkeyList, it always seems to call monkeyList[0].
I'm guessing that I am misunderstanding the way that these objects relate to each other, but I am new to Python and OOP so I can't see the wood for the trees! Apologies if this post doesn't explain my situation very well - I've tried to create a simplified example!
Thanks in advance for any advice.
I have a class which contains a list:
Code:
class Monkey:
__hairsList = []
__totalHairs = int(0)
__monkeyNum = int(0)
def init(self, monkeyNum, totalHairs):
self.__monkeyNum = monkeyNum
self.__totalHairs = totalHairs
self.getInitialHairs()
def getInitialHairs(self):
for i in xrange (0, self.totalHairs):
self.hairsList.append(Hair(i))
return self.hairsList
def getHairs(self):
return self.__hairsList
Code:
class Zoo:
monkeyList = []
__totalMonkeys = int(0)
def init(self, totalMonkeys):
self.__totalMonkeys = totalMonkeys
self.getInitialMonkeys()
def getInitialMonkeys(self):
totalHairs = 10000
for i in xrange (0, self.__totalMonkeys):
self.monkeyList.append(Monkey(i, totalHairs))
return self.monkeyList
Now my problems comes when I try to run something like this:
Code:
newArea = Zoo(53)
newArea.monkeyList[1].hairsList[0].getHairs()
I'm guessing that I am misunderstanding the way that these objects relate to each other, but I am new to Python and OOP so I can't see the wood for the trees! Apologies if this post doesn't explain my situation very well - I've tried to create a simplified example!
Thanks in advance for any advice.