Python Forum

Full Version: List of Objects print <__main. Problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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) [__, __, __, __, __, __, __, __, __, __]
Pages: 1 2