-1

So let's say i have the current code:

import time

now = time.time()
future = now + 10
while time.time() < future:
    print(time.time())
    pass

and when running it, i get:

1602289187.9999743
1602289187.999989
1602289188.000001
1602289188.0000124
1602289188.0000281
1602289188.0000439
1602289188.0000587
1602289188.0000732
1602289188.0000875
1602289188.0001028
1602289188.0001178
1602289188.0001347
...

As result. Now what i want is to only show the updated string, without showing previous one (basically without printing the new result on a newline, but replacing the old one instead, and only showing a single line with updated count).

How can i do that?

Nordine Lotfi
  • 463
  • 2
  • 5
  • 20

1 Answers1

1

You can use the curses library

import time
import curses
screen = curses.initscr()
now = time.time()
future = now + 10
while time.time() < future:
    screen.erase()
    screen.addstr(str(time.time()))
    screen.refresh()
    pass
curses.endwin()
EliKor
  • 199
  • 3
  • This is nice! But any ways to make the output more smooth? (since it flash quite fast, probably because of `screen.refresh` :/) – Nordine Lotfi Oct 10 '20 at 01:49
  • 1
    Unfortunately not that I know of :(. I also edited to change screen.clear() to screen.erase() which might fix the issue – EliKor Oct 10 '20 at 02:05