Jul-17-2020, 01:51 PM
Hello,
i am starting to learn python. For a better understanding i want to implement a genetic Algorithm. But acutally i am having troubles with my code.
So i create an instance of the class Chromosom and LKW and add them to the list polulation.
Then i want to print population, but i can only see:
"<__main__.Chromosom object at 7asd711yx2d"
What can i do to see the real numbers of population? +
Greetings Kol789
i am starting to learn python. For a better understanding i want to implement a genetic Algorithm. But acutally i am having troubles with my code.
So i create an instance of the class Chromosom and LKW and add them to the list polulation.
Then i want to print population, but i can only see:
"<__main__.Chromosom object at 7asd711yx2d"
What can i do to see the real numbers of population? +
Greetings Kol789
class Chromosom(object): #Chromosom wird erstellt mit Fitness,Index, Chromosom def __init__(self, fitness, index, chromosom): self.fitness=fitness self.index=index self.chromosom= chromosom def myfunc(self): # Printe ein Chromosom print(self.fitness,self.index,self.chromosom ) def __str__(self): return "<Test a:%s b:%s c:%s>" % (self.fitness, self.index, self.chromosom) class LKW(object): # Erzeuge LKW mit Uhrzeit def __init__(self, uhrzeit): self.uhrzeit=uhrzeit def __str__(self): return "<Test a:%s>" % (self.uhrzeit) population=[] p1= Chromosom(1,5,[123456]) print(p1) p2=LKW(12) print(p2) population.append(p1) population.append(p2) print(population)