A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/308781.html below:

No newline using printf

No newline using printf No newline using printfPeter Hansen peter at engcorp.com
Thu Sep 15 22:47:41 EDT 2005
Johnny Lee wrote:
> Roy Smith wrote:
> 
>>For closer control over output, use the write() function.  You want
>>something like:
>>
>>import sys
>>for i in range(3):
>>   sys.stdout.write (str(i))
> 
> 
> here is the output of my machine:
> 
>  >>> import sys
>  >>> for i in range(3):
>  ...     sys.stdout.write(str(i))
>  ...
>  012>>>
> 
> Why the prompt followed after the output? Maybe it's not as expected.

Because, unlike print, sys.stdout.write() just sends the raw bytes 
directly to the output without special formatting, extra characters 
(such as the newline print adds for you), or other interference.

Add the newline yourself after the loop to fix this:

sys.stdout.write('\n')

-Peter

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4