By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,930 Members | 1,508 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,930 IT Pros & Developers. It's quick & easy.

Re: Intercepting printed strings

P: n/a
En Thu, 18 Sep 2008 19:24:26 -0300, Robert Dailey <rc******>
I'm currently using Python 3.0 b3 and I'm curious as to how I can go
intercepting things send to print() for some intermediate processing
they're actually sent to sys.stdout. Right now I've thought of the

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

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.
Why don't you try it yourself?
You may replace builtins.print with your own function too. It's not
exactly the same thing, but given your request "intercepting things send
to print() before they're sent to sys.stdout" it may be more adequate.

Gabriel Genellina

Sep 19 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.