Jovito Jovito - 2 months ago 7
Python Question

Is there a way to clean output on command prompt programmatically?

Is there a way to programmatically clean output on command prompt as to be able to print each letter of a word than erase them one at a time in the same line?

Answer

Something like this?

from sys import stdout
from time import sleep

def show(word):
  for char in word:
    stdout.write(char)
    stdout.flush()
    sleep(1)
  for char in word:
    stdout.write('\b \b')
    stdout.flush()
    sleep(1)

show('hello')
Comments