1
import time
while True:
    time.sleep(1)
    print(".", end=" ")

I just want to make kind of loading screen by make dots appear after one second and I was expecting this-

.{wait}.{wait}.{wait}.{wait}

But I didn't got any output but after closing program by ctrl + c I got the output like this-


. . . . . . . . . . . . Traceback (most recent call last):
  File "c:/Users/Piyush/Desktop/Python/dotdotdotload.py", line 12, in <module>
    time.sleep(1)
KeyboardInterrupt```

Piyush
  • 177
  • 1
  • 8

1 Answers1

1

You need to flush the output and it will display:

Python-3.x: https://repl.it/repls/DarksalmonFussyBooleanalgebra

import time

while True:
    time.sleep(1)
    print(".", end=" ", flush=True)

Python-2.7: https://repl.it/repls/CuteTenseRoutes

import sys
import time

while True:
    time.sleep(1)
    print ". ",
    sys.stdout.flush()
Alan Kavanagh
  • 9,425
  • 7
  • 41
  • 65