Python Forum
List of Objects print <__main. Problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List of Objects print <__main. Problem
#7
Hello buran,

this is acutally my code:

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 __repr__(self, fitness, index, chromosom):
    return "<a:%s, b:%s, c:%s, d:%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)
But when i print the population i get an error __repr__ missing 3 required positional arguments in line 25 print(p1)
What am i doing wrong?
Reply


Messages In This Thread
List of Objects print <__main. Problem - by Kol789 - Jul-17-2020, 01:51 PM
RE: List of Objects print <__main. Problem - by Kol789 - Jul-20-2020, 02:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with print formatting using definitions Tberr86 2 2,068 Mar-20-2021, 06:23 PM
Last Post: DPaul
  How to print all iterations of min and max for a 2D list alaina 4 2,983 Nov-11-2020, 05:53 AM
Last Post: alaina
  Why does this function print empty list? hhydration 1 1,579 Oct-28-2020, 02:03 AM
Last Post: deanhystad
  How can I print the number of unique elements in a list? AnOddGirl 5 3,371 Mar-24-2020, 05:47 AM
Last Post: AnOddGirl
  Highscore problem, need to print top 5 Camiosobro123 1 1,616 Jan-27-2020, 10:43 PM
Last Post: Camiosobro123
  sorting a deck of cards (objects in a list) itmustbebunnies 1 7,287 Dec-05-2018, 02:44 AM
Last Post: ichabod801
  another positional argument error (...and executing objects stored in a list) itmustbebunnies 7 4,311 Nov-16-2018, 07:18 PM
Last Post: itmustbebunnies
  Print The Length Of The Longest Run in a User Input List Ashman111 3 3,263 Oct-26-2018, 06:56 PM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020