I'm working on this OOP program in Python
class SimpleString():
popSize = 1000 #Should be even number
displaySize = 5
alphatbet = "abcdefghijklmnopqrstuvwxyz "
def __init__(self):
pop = numpy.empty(self.popSize, object)
target = self.getTarget()
targetSize = len(target)
def genNewPop(self):
for i in xrange(self.popSize):
pop[i] = Item(self.genNewString())
def genNewString(self):
s = ""
for i in xrange(targetSize):
s += chr(random.randint(len(alphabet)))
return s
def main():
ss = SimpleString()
ss.genNewPop()
main()
In the genNewString(self) method it keeps telling me the instance variable targetSize is not defined! I tried putting self.targetSize in its place but then I get an error SimpleString instance has no attribute 'targetSize' even though it is assigned as an instance variable.