How To/python/

@None sys.stdout.write(str text)@

Writes text to standard output.

import sys
 
sys.stdout.write("This")
sys.stdout.write("Is")
sys.stdout.write("Single")
sys.stdout.write("Line")
 
#prints ThisIsSingleLine to the console

Examples

Redirect standard output

import sys
 
class iPrint():
    def __init__(self):
        self.oldout = sys.stdout
 
    def write(self, t):
        """ You can write t to file for example and then... """
        self.oldout.write("> I print: %s\n" % t) # write it to console
 
sys.stdout = iPrint()
print 'What do you say?'

It will give output:

> I print: What do you say?
> I print:

Why? Becouse @print@ adds new line at the end. @print 'x'@ is equal to: @sys.stdout.write('x'); sys.stdout.write("\n")@.
You can for example use it to redirect output to file and screen, so every @print@ will be logged to file.