creating class objects inside methods

Carl Banks pavlovevidence at
Sun Oct 4 21:40:49 CEST 2009

On Oct 4, 3:12 am, Albert Hopkins <mar... at> wrote:
>       * You define a to_string() method. To have a string representation
>         of a class, one usually defines a __str__ method.  This gives
>         the advantage whereby "print myobject" or '%s' % myjobject just
>         work.

In fairness, a lot of types define a to_string() method (especially
third-party types like numpy), but it's usually to produce a raw
binary output.

Presumably in Python 3 these methods will be renamed to_bytes.

Carl Banks

More information about the Python-list mailing list