how to stop info output on screen

Discussion in 'Python' started by midday.hu@gmail.com, Sep 30, 2005.

  1. Guest

    Hi,

    Does someone know how to stop "the information output on screen"? Now
    when I run my code, it outputs a lot of message when calling other
    libraries, together with the info with the print command I used.

    How can I mask these info on screen when calling other libraries and
    how I can mask the info output produced by the print command? Is there
    a way to mask them separately.

    Thanks a lot if anyone knows it.

    Kind regards of your help
    Midday
     
    , Sep 30, 2005
    #1
    1. Advertising

  2. Guest

    maybe you can try replaceing sys.stdout and/or sys.stderr with a just a
    simple file? then everything will be written to that file instead of
    desplayed on the console.

    Cheers,
    Ido.
     
    , Sep 30, 2005
    #2
    1. Advertising

  3. Guest

    more on the subject: your "print" statments will also be written to
    that file that sys.stdout directs to, so maybe that wasn't exactly the
    solution you wanted to hear.

    ok, not the nicest solution but maybe it will help you anyway:
    bind sys.stdout at the begining of the program to a file (don't forget
    to save it first! let's say stdout = sys.stdout;
    sys.stdout=file('myLogFile.dat','w') ), and write your own print
    funktion that goes something like that:
    def printToConsole(stringToPrint,oldStdOut):
    ____sys.stdout=oldStdOut
    ____print stringToPrint
    ____sys.stdout=file('myLogFile.dat','w')

    then when you want to print to the console, use this function instead
    of the print statment. all the rest will go to 'myLogFile.dat'

    Cheers,
    Ido.
     
    , Sep 30, 2005
    #3
  4. Steve Holden Guest

    wrote:
    > Hi,
    >
    > Does someone know how to stop "the information output on screen"? Now
    > when I run my code, it outputs a lot of message when calling other
    > libraries, together with the info with the print command I used.
    >
    > How can I mask these info on screen when calling other libraries and
    > how I can mask the info output produced by the print command? Is there
    > a way to mask them separately.
    >
    > Thanks a lot if anyone knows it.
    >
    > Kind regards of your help
    > Midday
    >

    Since you appear to be adding your own code, with your own print
    statements, to an existing Python program the easiest thing to do is
    make sure your own code writes to a place of your choice. This is most
    easily done with

    myFile = open("myfile.txt", "w")
    ...
    print >> myFile, this, that, the other
    ...
    print >> myFile, moreStuff(things)
    ...
    myFile.close()

    regards
    Steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC www.holdenweb.com
    PyCon TX 2006 www.python.org/pycon/
     
    Steve Holden, Sep 30, 2005
    #4
  5. Guest

    forget my posts, Steve's solution is much more maintanable when you(or
    someone else)'ll revisit the code in a couple of years.

    i would go with what he wrote.

    Cheers,
    Ido.
     
    , Sep 30, 2005
    #5
    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. Matt Theule

    Stop Debugging doesn't stop in ASP.NET

    Matt Theule, Jul 23, 2003, in forum: ASP .Net
    Replies:
    7
    Views:
    744
    Matt Theule
    Jul 24, 2003
  2. Son KwonNam
    Replies:
    11
    Views:
    2,613
    mr_organic
    Apr 9, 2004
  3. Will
    Replies:
    1
    Views:
    15,263
    Thomas Weidenfeller
    Nov 2, 2004
  4. chuck amadi
    Replies:
    1
    Views:
    494
    Larry Bates
    Jun 23, 2004
  5. Mav
    Replies:
    22
    Views:
    371
Loading...

Share This Page