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()
4

3 回答 3

1

这是我的尝试:

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

我相信在 Python 中有更好的方法来做到这一点。我没有太多地使用这门语言,但这来自我所知道的和我在其他语言方面的背景。

于 2013-10-31T21:32:46.677 回答
0

你需要清屏,如果你在linux系统上,只需使用os库

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>
于 2013-10-31T21:45:28.617 回答
0

要做这样的事情,你真的应该使用 curses 库。有一些技巧可以清除屏幕或退格字符,但没有一个可以与 curses 的 UI 功能相比:

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

于 2013-10-31T22:25:08.613 回答