redirect python output + extension type with own print method = FAILS

Guido van Rossum guido at
Sat Aug 11 14:58:39 CEST 2001

Donn Cave <donn at> writes:

> BOTTOMLINE ANSWER:  If you want to say "print xxx" and have the
> output go through your stdout - you don't really want a "print"
> method, you want a "repr" method.  No I/O, just return a string
> (as in PyString_FromString().)  The "print" statement does all the I/O.

Exactly, except strictly speaking, you need a "str" method.

Specifically, the print method only works if sys.stdout is a stdio
file object.

--Guido van Rossum (home page:

More information about the Python-list mailing list