__str__ difficulty with lists

Diez B. Roggisch deets at nospam.web.de
Sun Nov 1 16:26:33 EST 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