sys.stdout.write() question

Reinhold Birkenfeld reinhold-birkenfeld-nospam at wolke7.net
Mon Jun 21 16:20:37 CEST 2004


Gian Mario Tagliaretti wrote:
> Hi all,
> 
> It is (I hope) a simple question,
> I cannot figure out why sys.stdout.write() doesn't print immediatly the first 
> text in the small example below, but before it process the code in between 
> and then print both lines in one time.
> 
> #!/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.

Apparently the stdout "file" is buffered on your system. Have a look at
file.flush() which could help you out.

Reinhold

-- 
Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows
mitbrächte, wäre das bedauerlich.  Was bei Windows der Umfang eines
"kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk.
  -- David Kastrup in de.comp.os.unix.linux.misc



More information about the Python-list mailing list