Reputation: 53
Example:
First output: 1 Second output: 2 Third output: 3 Remains in the same line
NOT: 123
Upvotes: 2
Views: 276
Reputation: 60954
Are you set on using \b
? You can use \r
to move the cursor back to the beginning of the line, which will let you write over stuff that is already there. If there's a chance that later lines will be shorter than previous ones, you should pad the new lines with whitespace on the right. Something like:
def f(x):
for i in range(1, x+1):
print(end='\r', flush=True)
print('**{}**'.format(i), end='', flush=True)
time.sleep(1)
f(3)
Upvotes: 1