1

so i want to output '|' and the remove it and paste '/' instead (in one line) so it will make animation.

import time


animation = '|'
print(animation)

time.sleep(0.5)

animation = animation.replace('|', '/')
print(animation)
daniel
  • 61
  • 1
  • 7

1 Answers1

0

In a nutshell, you need to output \r character, which is a carriage RETURN command. It will put the caret to the start of the line in the console. Next output will basically rewrite the line contents.

import sys, time

i = 0
while True:
    sys.stdout.write('/-\\|'[i%4])
    time.sleep(0.5)
    sys.stdout.write('\r')
    i += 1
VisioN
  • 143,310
  • 32
  • 282
  • 281