sys.stdout.write() question

Ivan Voras iv at an.voras.fer.hr
Mon Jun 21 10:13:53 EDT 2004


Gian Mario Tagliaretti wrote:

> #!/usr/bin/env python
> import sys, time
> sys.stdout.write('write ')
> time.sleep(3)
> sys.stdout.write('this\n')
> 
> if you try to run this, before it will wait 3 seconds and then print "write 
> this" in one time.
> 
> If I put \n here :
> 
> sys.stdout.write('write \n')
> 
> it work properly but I would like to print the text in one row.

It line-buffers the output. If you need to print something that is not 'a 
whole line', use sys.stdout.flush() after the ...write()




More information about the Python-list mailing list