I am looking for a method so that when something is printed continuously, it overwrite what the previous printed statement says. for example, if I am making a counter, normally the outcome in the IDLE would be: 1 2 3 4...., but however I'm looking to rewrite/overwrite what the previous printed statement says so it say "1" for a second then "2" appears but we can no longer see "1". Any suggestions? Sorry about how wordy this question is, I was having a hard time trying to write this where another person understands.
Asked
Active
Viewed 99 times
0
-
https://stackoverflow.com/questions/5290994/remove-and-replace-printed-items – ruslan_krivoshein Nov 23 '19 at 08:27
1 Answers
1
import time
arr = [1,2,3,4]
for element in arr:
print(element, end='\r')
time.sleep(1)
end='\r'
in the print statement does the trick

ProblemSolver
- 74
- 2
-
This fails to overwrite the entire line, for example if your `arr` is `[1234, 999, 5, 2]` – Ofer Sadan Nov 23 '19 at 08:33
-
Yeah, I'm looking to rewrite the entire line but the bit of code provided can be useful for another project. thank you – Evan Dilkes Nov 23 '19 at 08:40