Can a print overwrite a previous print ?

Cameron Simpson cs at cskk.id.au
Fri May 8 20:02:36 EDT 2020


On 08May2020 09:36, Sir Real <nomail at adres.net> wrote:
>On Fri, 8 May 2020 16:25:52 +0200, ast <ast at invalid> wrote:
>>Suppose we want that:
>>
>>print("abcdef"); print("ghi")
>>
>>produces:
>>
>>ghidef
>>
>>The 2nd print overwrites the first one.
>>Is it feasible ?

On a terminal, yes. This is a display issue.

>>It should since the progress bar tdqh seems to do that
>>
>>try:
>>from tkdm import tkdm
>>for i in tqdm(range(100_000_000)):
>>     pass
>>It produces a progress bar like this:
>>100%|???????????????????????????????????????????????????????????????|
>>100000000/100000000 [00:56<00:00, 1781611.52it/s]
>
>
>print('abcdef', end='\r'); print('ghi', end='')

Aye, though that is the (hated by me) rewrite-the-whole-line brute force 
approach.

I've got a module "cs.upd" on PyPI which does this with minimal 
overwrites if you want something eaier on the eyes. Doubtless there are 
others.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list