My problem is that I want to be able to overwrite / clear the previous print line in the python console. This question has been asked many times ( Python - remove and replace print elements ), but with the same code that (the answer is marked as correct, it doesn’t display anything for me):
for i in range(10):
print("Loading" + "." * i)
time.sleep(1)
sys.stdout.write("\033[F")
sys.stdout.write("\033[K")
I get the output (in python IDLE):
Loading
[F[KLoading.
[F[KLoading..
[F[KLoading...
[F[KLoading....
[F[KLoading.....
[F[KLoading......
[F[KLoading.......
[F[KLoading........
[F[KLoading.........
[F[KLoading..........
[F[K
Any ideas? I google a lot, nothing works. It either does not print anything, or simply does not overwrite.
If this helps, I am running Windows 8.1 and Python 3.51. Running the cmd code trough has no effect.
In addition, the addition sys.stdout.flush()does not help.
source
share