0

I am trying to print sequence of numbers in one line dynamically

p=['3.333','2.22','1.1']
for d in p:
    time.sleep(0.1)
    sys.stdout.write('\r'+d)
    sys.stdout.flush()

But the output is not as expected.

At last we get:

1.123

Actually I want it to be 1.1 , So how do I remove the existing Characters?

Yashik
  • 391
  • 5
  • 17
  • You delete each character - \r just jumps to the start of the line. You could also simply print enough spaces after each number to overwrite the last numbers digits - for your example something like `sys.stdout.write('\r'+d+" "*10)` shoiuld suffice – Patrick Artner Aug 26 '18 at 07:42
  • @PatrickArtner nice dupe find – Jean-François Fabre Aug 26 '18 at 07:44
  • @Jean-FrançoisFabre thanks - this kind of question mostly pops up with "I want to print the time and change the seconds"-kind of tasks, there are several of those answered already, this dupe was just the one I found first ;) – Patrick Artner Aug 26 '18 at 07:46

0 Answers0