Hello,
I am new to Python programming so please excuse what may be a simple question:
I have created a class which contains a list of other classes, e.g.
class Monkey:
hairsList = []
totalHairs = int(0)
def __init__(self, totalHairs):
self.hairsList = self.getHairs()
self.totalHairs = totalHairs
def getHairs(self):
for i in xrange (0, self.totalHairs):
self.hairsList.append(Hair(i))
class Hair:
hairNumber = (0)
def __init__(self, hairNum):
self.hairNumber = hairNum
I then want to be able to access individual properties of specific classes. I create a Monkey instance and attempt to access the individual parts of its hair, e.g.
ape= Monkey(2000)
print ape.hairsList[50]
However, I am getting an error: 'TypeError: 'NoneType' object is not subscriptable'.
Is there a way of accessing objects in this manner? Am I approaching this problem in completely the wrong way?
Thanks in advance for any help!
I am new to Python programming so please excuse what may be a simple question:
I have created a class which contains a list of other classes, e.g.
class Monkey:
hairsList = []
totalHairs = int(0)
def __init__(self, totalHairs):
self.hairsList = self.getHairs()
self.totalHairs = totalHairs
def getHairs(self):
for i in xrange (0, self.totalHairs):
self.hairsList.append(Hair(i))
class Hair:
hairNumber = (0)
def __init__(self, hairNum):
self.hairNumber = hairNum
I then want to be able to access individual properties of specific classes. I create a Monkey instance and attempt to access the individual parts of its hair, e.g.
ape= Monkey(2000)
print ape.hairsList[50]
However, I am getting an error: 'TypeError: 'NoneType' object is not subscriptable'.
Is there a way of accessing objects in this manner? Am I approaching this problem in completely the wrong way?
Thanks in advance for any help!