__str__ difficulty with lists

Diez B. Roggisch deets at nospam.web.de
Sun Nov 1 22:26:33 CET 2009


Jabba Laci schrieb:
> Hi,
> 
> I have a list that contains custom objects. When printing the list,
> I'd like to have a readable result, i.e. I'd like to see the output of
> the __str__ functions. See an example below. When I call "print li", I
> would like to get "[3, 5]". How to do that?

Use __repr__ instead - lists call that on their contained objects.


Diez



More information about the Python-list mailing list