On Sat, Mar 10, 2018 at 5:10 AM, Paul Moore <p.f.mo...@gmail.com> wrote:
> On 9 March 2018 at 17:46, Rob Gaddi <rgaddi@highlandtechnology.invalid> wrote:
>> On 03/08/2018 07:57 PM, Steven D'Aprano wrote:
>>>
>>> [snip]
>>>
>>> But it is possible that due to differences between platforms, the
>>> OP's version of IDLE doesn't display a carriage return as \r but
>>> rather as an invisible zero-width space.
>>>
>>
>> Just to derail this conversation a bit, does anyone have a use case in the
>> modern (Py3) age for '\r'?  I use b'\r' fairly regularly when talking to
>> serial port devices.  But the string version?
>
> It's fairly common for backing up and rewriting a progress line in
> simple console programs:
>
> for i in range(100):
>     print(f"\r              \rCompleted: {i}%", end='')
>     sleep(0.5)
>

Yep, though I prefer end="\r" (or end="\33[K\r" if you can use ANSI
codes) rather than putting the \r at the beginning. It looks nicer to
have the cursor at the end of the line (which your way does, but mine
doesn't), but on the other hand, leaving the cursor at the beginning
means that any output lines (ending with a normal \n) will more
cleanly overwrite the completion percentage line. It's tradeoffs all
around, as always.

But yes, that's one VERY common use of \r.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to