Answer the question
In order to leave comments, you need to log in
Why does the NoneType error appear?
I just started learning python an hour ago) I don't understand the behavior of the compiler... I created a class:
class Specie:
def __init__(self, x, y, z, t):
self.x = x
self.y = y
self.z = z
self.t = t
self.fitness = None
self.reproductionProbability = None
def fitness(self):
self.fitness = 1 / Genetic.calcF(self) //вызываю статический метод другого моего класса
return self.fitness
def reproductionProbability(self):
self.reproductionProbability = self.fitness/Genetic.totalFitness
return self.reproductionProbability
specie = Specie(10, 2, 4, 5)
print(specie.fitness())
Traceback (most recent call last):
File "/Users/nikita/Desktop/Python/geneticAlg/index.py", line 71, in <module>
print(specie.fitness())
TypeError: 'NoneType' object is not callable
Answer the question
In order to leave comments, you need to log in
For starters, python is not a compiled language.
Then you first created a method called fitness, and then in __init__ you redefined it to None
self.fitness = None
, it's all logical that you have an error.
Do not do it this way
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question