1
I have a python loop, and would like to inform the value of a variable each time it is updated, however I don’t want to dirty the console printing every time and or clean the whole console.
There is a way I can get this result?
print("Executando processo:")
while True:
a = a +1
print a
The result at the end of 3 interactions is:
Interaction 1:
$ - Executando processo:
$ - 1
Interaction 2:
$ - Executando processo:
$ - 1
$ - 2
Interaction 3:
$ - Executando processo:
$ - 1
$ - 2
$ - 3
And I would like to get the following result:
Interaction 1:
$ - Executando processo:
$ - 1
Interaction 2:
$ - Executando processo:
$ - 2
Interaction 3:
$ - Executando processo:
$ - 3
It is important to stress that this process only works if the new text is larger or equal to the previous one. If it is not, characters from the last text will remain displayed as
\r
just returns the cursor to the beginning of the line, but does not delete its contents. If there is no such guarantee in the system, the best solution is to use the one I have presented here.– Woss
I was going to add blanks to avoid this, but I thought it would unnecessarily complicate the understanding.
– fernandosavio
As soon as I arrive on the PC I edit the response to cover that case
– fernandosavio