Intercepting printed strings

Robert Dailey rcdailey at gmail.com
Thu Sep 18 18:24:26 EDT 2008


Hi,

I'm currently using Python 3.0 b3 and I'm curious as to how I can go about
intercepting things send to print() for some intermediate processing before
they're actually sent to sys.stdout. Right now I've thought of the
following:

Replace sys.stdout with a class named PrintStream. PrintStream is defined as
follows:

class PrintStream:
    def write( self, message ):
        sys.__stdout__.write( '\t{0}'.format( message ) )

Will this work? Basically I want to add a tab character in front of every
message printed. Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080918/572b3b99/attachment.html>


More information about the Python-list mailing list