Re: print to screen and file with one print statement

Discussion in 'Python' started by amiwinter@gmail.com, Apr 9, 2013.

  1. Guest

    On Thursday, February 13, 2003 2:51:02 PM UTC+2, Mike Müller wrote:
    > "Mark McEahern" <> wrote in message news:<>...
    > > Same basic idea:
    > >
    > > #!/usr/bin/env python
    > >
    > > import sys
    > >
    > > class MyWriter:
    > >
    > > def __init__(self, stdout, filename):
    > > self.stdout = stdout
    > > self.logfile = file(filename, 'a')
    > >
    > > def write(self, text):
    > > self.stdout.write(text)
    > > self.logfile.write(text)
    > >
    > > def close(self):
    > > self.stdout.close()
    > > self.logfile.close()
    > >
    > > writer = MyWriter(sys.stdout, 'log.txt')
    > > sys.stdout = writer
    > >
    > > print 'test'
    > >

    >
    > Hi Mark,
    >
    > works perfect. Just had to change ´file´ to ´open´ for my Python 2.1.
    > Adding the method ´flush(self)´ to Writer helped to get my
    > ´sys.stdout.flush()´ to work.
    >
    > Thanks also to two inches (previous post).
    >
    >
    > Mike


    Hay Mike,

    Can you tell me how & where you added the 'flush(self)' & 'sys.stdout.flush()'?


    Thanks!
    Ami
    , Apr 9, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bryan Shaw

    Lock Print Screen and File Print

    Bryan Shaw, Apr 19, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    3,924
    Kevin Spencer
    Apr 20, 2005
  2. loveNUNO
    Replies:
    2
    Views:
    884
    loveNUNO
    Nov 20, 2003
  3. arvind
    Replies:
    4
    Views:
    20,986
    Kevin Goodsell
    Oct 4, 2003
  4. keto
    Replies:
    0
    Views:
    883
  5. Biranchi Narayan Panda
    Replies:
    1
    Views:
    2,707
    Alexey Smirnov
    Feb 17, 2010
Loading...

Share This Page