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
#11
You're right. If it's an container, the repr of the elements is printed.

Example:
Output:
In [1]: class Foo: ...: def __str__(self): ...: return "__" ...: In [2]: print([Foo()] * 10) [<__main__.Foo object at 0x7f60b712ccd0>, <__main__.Foo object at 0x7f60b712ccd0>, <__main__.Foo object at 0x7f60b712ccd0>, <__main__.Foo object at 0x7f60b712ccd0>, <__main__.Foo object at 0x7f60b712ccd0>, <__main__.Foo object at 0x7f60b712ccd0>, <__main__.Foo object at 0x7f60b712ccd0>, <__main__.Foo object at 0x7f60b712ccd0>, <__main__.Foo object at 0x7f60b712ccd0>, <__main__.Foo object at 0x7f60b712ccd0>] In [3]: class Foo: ...: def __str__(self): ...: return "__" ...: __repr__ = __str__ ...: In [4]: print([Foo()] * 10) [__, __, __, __, __, __, __, __, __, __]
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with print formatting using definitions Tberr86 2 2,010 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,909 Nov-11-2020, 05:53 AM
Last Post: alaina
  Why does this function print empty list? hhydration 1 1,534 Oct-28-2020, 02:03 AM
Last Post: deanhystad
  How can I print the number of unique elements in a list? AnOddGirl 5 3,272 Mar-24-2020, 05:47 AM
Last Post: AnOddGirl
  Highscore problem, need to print top 5 Camiosobro123 1 1,570 Jan-27-2020, 10:43 PM
Last Post: Camiosobro123
  sorting a deck of cards (objects in a list) itmustbebunnies 1 7,199 Dec-05-2018, 02:44 AM
Last Post: ichabod801
  another positional argument error (...and executing objects stored in a list) itmustbebunnies 7 4,207 Nov-16-2018, 07:18 PM
Last Post: itmustbebunnies
  Print The Length Of The Longest Run in a User Input List Ashman111 3 3,203 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