how to stop info output on screen

M

midday.hu

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
 
I

Ido.Yehieli

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.
 
I

Ido.Yehieli

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.
 
S

Steve Holden

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
 
I

Ido.Yehieli

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top