-2

I have write a simple python program

import sys
from time import sleep

def main():
   for i in range(11):
      sys.stdout.write("The value is %d"%int(i))
      sleep(1)
      sys.stdout.flush()
      
if __name__=="__main__":
   main()

It give me the following output with delay of 1s between each loop

The value is 0The value is 1The value is 2The value is 3The value is 4The value is 5The value is 6The value is 7The value is 8The value is 9The value is 10

but i need an output like this

This is 1

After 1s 1 should replaced by 2 in same place If you did not understand my situation see my wordlist generator at https://github.com/azan121468/wordlist_gen I want to apply same thing in my simple program but i am unable to do it Please help me

1 Answers1

-1

It is possible to use the backspace ('\b') character:

from time import sleep


def main():
    print('The value is 0', end='')
    for i in range(1, 11):
        print('\b' + str(i), end='')
        sleep(1)


if __name__ == "__main__":
    main()
Rafael Setton
  • 352
  • 1
  • 8