__str__ vs. __repr__

Bernhard Herzog herzog at online.de
Thu Nov 4 16:13:12 CET 1999

"Thomas Heller" <thomas.heller at ion-tof.com> writes:

> > How about a hook function a la __import__? I.e. have a function
> > __format__ [1] in __builtin__ that is bound to repr by default. Whenever
> > Python prints the result of an expression in interactive mode, it calls
> > __format__ with the result as parameter and expects it to return a
> > string ready for printing.
> But you have a custom python interpreter, don't you?

No, I haven't.

> Or how do you
> manage to use your __format__ as the printer for interactive mode?

My phrasing might have been a bit misleading. I meant it as a suggestion
how to deal with the different user preferences when it comes to format
the result in interactive mode for printing. The python interpreter
would have to be changed if my suggestion were adopted.

Bernhard Herzog	  | Sketch, a drawing program for Unix
herzog at online.de  | http://www.online.de/home/sketch/

More information about the Python-list mailing list