Dave Angel davea at
Sat Oct 17 05:39:38 CEST 2009

mattia wrote:
> Is there a way to print to an unbuffered output (like stdout)? I've seen 
> that something like sys.stdout.write("hello") works but it also prints 
> the number of characters!
What the other responses (so far) didn't address is your comment about 
"prints the number of characters."

You're presumably testing this in the interpreter, which prints extra 
stuff.  In particular, it prints the result value of any expressions 
entered at the interpreter prompt.  So if you type


then after the write() method is done, the return value of the method 
(5) will get printed by the interpreter.

Either put the statement in a real script, or do the following trick to 
convince yourself:

dummy = sys.stdout.write("hello")


More information about the Python-list mailing list