On 2009-10-17, Dave Angel <da...@ieee.org> wrote: > 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 > > sys.stdout.write("hello") > > then after the write() method is done, the return value of the method > (5) will get printed by the interpreter.
Except sys.stdout.write("hello") doesn't return 5. It returns None. I don't know what the OP is talking about when he says "prints the number of characters": $ python Python 2.6.2 (r262:71600, Aug 25 2009, 22:35:31) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.stdout.write("hello\n") hello >>> >>> > Either put the statement in a real script, or do the following trick to > convince yourself: > > dummy = sys.stdout.write("hello") I don't see why the assignment is needed. -- Grant -- http://mail.python.org/mailman/listinfo/python-list