0
from time import sleep

for _ in range(10):
    for i in '|/-\\':
        print(i, end='')
        sleep(2)
        print('\b', end='')

Shouldn't this print a character then wait for 2 seconds and then delete it and start again?

For me this code runs with a blank line and only gives an output when its finished or stopped in middle. I've tried it on cmd and powershell

Aditya Singh
  • 40
  • 1
  • 6

2 Answers2

1

Try this:

from time import sleep
import sys

for _ in range(10):
    for i in '|/-\\':
        sys.stdout.write(i)
        sleep(2)
        print('\b', end='')
Abhinav Dhiman
  • 745
  • 3
  • 17
1

Use print(i, end='\r') and remove print('\b', end='')

Reshab Das
  • 185
  • 7