For loop printing memory location of class instead of list

后端 未结 4 1298
不思量自难忘°
不思量自难忘° 2021-01-28 01:24

I have some code which seems to print [<__main__.TCar object at 0x0245C1B0>] but I want it to print the actual contents of the list.

class TCa         


        
4条回答
  •  囚心锁ツ
    2021-01-28 02:03

    You have a list of objects here. Add something like:-

    def __str__(self):
      print self.Make, self.Model, self.EngineSize, self.Price
    

    This would print the value of all attributes of object. Or you can modify the function as per your behavior requirement.

提交回复
热议问题