0

I am trying to make a python program that writes the follwing to a terminal:

Frame 1 -- Loading Frame 2 -- Loading. Frame 3 -- Loading.. Frame 4 -- Loading... Frame 5 -- Loading

This would all be a function so that it repeats itself. The one problem I am having is that I have no idea how to reset the number of dots to zero after they equal three. My current code is below, any suggestions would be nice.

import pickle
import time
from sys import stdout

stdout.write("Loading")
def loaddot():
    stdout.write(".")
    time.sleep(.5)
    loaddot()
loaddot()

3 Answers 3

1

Here is my attempt:

import time
from sys import stdout

def loaddot():
    stdout.write("."*(dots%3 + 1))
    time.sleep(.5)

dots = 0    
while(True):
    dots += 1
    stdout.write("Loading")
    loaddot()
    stdout.flush()
    print

I believe there are better ways to do it in Python. I have not worked with the language that much, but this comes from what I know and my background in other languages.

Sign up to request clarification or add additional context in comments.

Comments

0

To do something like this, you really should be using the curses library. There exist several hacks to get the screen to clear, or backspace characters, but none compare to the UI features of curses:

http://docs.python.org/2.7/library/curses.html

Comments

0

You need to clear the screen, if you are on a linux system simply use the os library

import os
import time

while True:
   for i in range(3):
      print "Loading."<br>
      time.sleep(3)<br>
      os.system("clear")<br>
print "Loading.."<br>
time.sleep(3)<br>
os.system("clear")<br>
print "Loading..."<br>
time.sleep(3)<br>
os.system("clear")<br>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.