Overwriting previous print in Python 3


It is required to show the progress of the execution especially in situations where the execution takes tens of seconds or more. The following python 3 code illustrates how to achieve this by overwriting the previously printed content.

print("Overwriting previous print")
for x in range(100000):
    print("Progress {:2.1%}".format(x / 100000), end="\r")

In case there are shorter print statements following longer print statements, a blank line can be printed and overwritten by the shorter print statement.

Reference: stackoverflow