printing list, is this a bug?

Robert Kern robert.kern at gmail.com
Fri May 25 18:54:14 EDT 2007


William Chang wrote:
> Is the different behavior between __repr__ and __str__ intentional
> when it comes to printing lists? Basically I want to print out a list
> with elements of my own class, but when I overwrite __str__, __str__
> doesn't get called but if I overwrite __repr__, __repr__ will get
> called. Is this a bug?

No, it's deliberate design. The string representation of a list object, either
list.__str__() or list.__repr__(), uses the __repr__() of its contained objects.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco




More information about the Python-list mailing list