print to console without a line break

Albert Hopkins marduk at letterboxes.org
Tue Dec 23 09:41:06 EST 2008


On Tue, 2008-12-23 at 13:18 +0000, Lie Ryan wrote:
> On Tue, 23 Dec 2008 11:50:59 +0100, Qian Xu wrote:
> 
> > Hello All,
> > 
> > Is it possible to print something to console without a line break?
> > 
> > I tried:
> >   sys.stdout.write("Testing something ...") // nothing will be printed
> >   time.sleep(1)
> >   sys.stdout.write("done\n") // now, the whole string will be printed
> > 

Probably because your stdout is line-buffered. Try:

sys.stdout.write("Testing something...")
sys.stout.flush() # flush the stdout buffer








More information about the Python-list mailing list