about __str__

Paul Hankin paul.hankin at gmail.com
Fri Sep 21 00:26:29 CEST 2007

On Sep 20, 10:08 pm, Konstantinos Pachopoulos <kostaspa... at yahoo.gr>
> The __str__ method of "list" doesn't seem to call the __str__ method of
> the objects....
> ie, __str__ is not equicalent to the Java toString() method... Anyway,
> how can i fix this?

For whatever reason, __str__ of list calls repr rather than str on
its elements.

You can fix your code by adding __repr__ in your class:

Class CmterIDCmts:
    def __init__ ...
    def __str__ ...

    __repr__ = __str__

Paul Hankin

More information about the Python-list mailing list