print to console without a line break

Lie Ryan lie.1296 at gmail.com
Tue Dec 23 14:18:32 CET 2008


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
> 
> What I want, is to see "Testing something ..." first. And after 1
> second, to see "done" (with a line break)
> 
> The only one solution I have found is to call "echo -n 'my_string'". But
> it is not nice. Because I have to escape all special chars in the string
> manually.
> 
> Any advice?
> Best regards
> -- Qian Xu

If you don't mind an extra space, you can use this:

print 'Testing something ...', 
# note the trailing comma




More information about the Python-list mailing list