0

So this is in Python and I'm trying to create a "loading screen" with repeated "..." where it outputs the "...", waits for a second, and replaces it with another "...", but maybe 1 dot at a time (haven't tried that yet). I just wanted to know if it's possible to do this and if so, how. Any help would be much appreciated. I've tried the below but it just repeats itself (which isn't surprising).

load = 0
while load != 3:
    loader = "..."
    print loader
    sleep(1)
    loader.replace("...", "   ")
    load = load + 1
Russell
  • 49
  • 1
  • 7
  • I guess that your code snippet is just a simple example, and your use case maybe a little bit diffrent, but have you looked at the tqdm package? – Kev1n91 Oct 03 '17 at 16:08
  • @Kev1n91 First off, thanks for your suggestion! I was just hoping to do it without external packages. Obviously, there's some library for everything and your suggestion totally works. – Russell Oct 03 '17 at 16:34
  • please accept one of the answers provided by the community – Kev1n91 Oct 03 '17 at 16:57

2 Answers2

1

You could do this with

from time import sleep
load = 0
dot_list = ['...', '.  ', '.. ']
while load <= 6:
    print(dot_list[load % len(dot_list)])
    sleep(1)
    load = load + 1

However, as @Kev1n91 said, you should check out the tqdm package and see if it does what you want better than this

Jeremy McGibbon
  • 3,527
  • 14
  • 22
0
from sys import stdout
from time import sleep


load = 0
while load != 3:
    stdout.write("\r..." + str( load))
    stdout.flush()
    #print(load)
    sleep(1)
    #stdout.flush()
    load = load + 1

This code example simply puts 3 dots, and then counts a number upwards so, "...1" followed by "...2" in the nexst line

from tqdm import tqdm


for load in tqdm(range(0,3)):
    sleep(1)

Is a neat tool I like to use in such cases.

If you wanna stick to your implementation you might found this thread useful: Print in one line dynamically

Kev1n91
  • 3,553
  • 8
  • 46
  • 96