Skip to main content
added code formatting
Source Link
efotinis
  • 15k
  • 6
  • 35
  • 36

One way to get unbuffered output would be to use sys.stderrsys.stderr instead of sys.stdoutsys.stdout or to simply call sys.stdout.flush()sys.stdout.flush() to explicitly force a write to occur.

You could easily redirect everything printed by doing:

import sys; sys.stdout = sys.stderr

print "Hello World!"

import sys; sys.stdout = sys.stderr print "Hello World!" 

Or to redirect just for a particular printprint statement:

print >>sys.stderr, "Hello World!"

print >>sys.stderr, "Hello World!" 

To reset stdout you can just do:

sys.stdout = sys.__stdout__

sys.stdout = sys.__stdout__ 

One way to get unbuffered output would be to use sys.stderr instead of sys.stdout or to simply call sys.stdout.flush() to explicitly force a write to occur.

You could easily redirect everything printed by doing:

import sys; sys.stdout = sys.stderr

print "Hello World!"

Or to redirect just for a particular print statement:

print >>sys.stderr, "Hello World!"

To reset stdout you can just do:

sys.stdout = sys.__stdout__

One way to get unbuffered output would be to use sys.stderr instead of sys.stdout or to simply call sys.stdout.flush() to explicitly force a write to occur.

You could easily redirect everything printed by doing:

import sys; sys.stdout = sys.stderr print "Hello World!" 

Or to redirect just for a particular print statement:

print >>sys.stderr, "Hello World!" 

To reset stdout you can just do:

sys.stdout = sys.__stdout__ 
escaped sys.__stdout__
Source Link
stderr
  • 8.8k
  • 1
  • 38
  • 51

One way to get unbuffered output would be to use sys.stderr instead of sys.stdout or to simply call sys.stdout.flush() to explicitly force a write to occur.

You could easily redirect everything printed by doing:

import sys; sys.stdout = sys.stderr

print "Hello World!"

Or to redirect just for a particular print statement:

print >>sys.stderr, "Hello World!"

To reset stdout you can just do:

sys.stdout = sys.stdoutsys.__stdout__

One way to get unbuffered output would be to use sys.stderr instead of sys.stdout or to simply call sys.stdout.flush() to explicitly force a write to occur.

You could easily redirect everything printed by doing:

import sys; sys.stdout = sys.stderr

print "Hello World!"

Or to redirect just for a particular print statement:

print >>sys.stderr, "Hello World!"

To reset stdout you can just do:

sys.stdout = sys.stdout

One way to get unbuffered output would be to use sys.stderr instead of sys.stdout or to simply call sys.stdout.flush() to explicitly force a write to occur.

You could easily redirect everything printed by doing:

import sys; sys.stdout = sys.stderr

print "Hello World!"

Or to redirect just for a particular print statement:

print >>sys.stderr, "Hello World!"

To reset stdout you can just do:

sys.stdout = sys.__stdout__

Source Link
stderr
  • 8.8k
  • 1
  • 38
  • 51

One way to get unbuffered output would be to use sys.stderr instead of sys.stdout or to simply call sys.stdout.flush() to explicitly force a write to occur.

You could easily redirect everything printed by doing:

import sys; sys.stdout = sys.stderr

print "Hello World!"

Or to redirect just for a particular print statement:

print >>sys.stderr, "Hello World!"

To reset stdout you can just do:

sys.stdout = sys.stdout