import sys
import time
data = ["b","u","f","f","e","r","i","n","g"]
# display with one upper char
for x in range(len(data)):
# remeber lower char
old = data[x]
# replace with upper char
data[x] = old.upper()
# create full text
text = "".join(data)
# display full text
sys.stdout.write("\r")
sys.stdout.write(text)
sys.stdout.flush()
# put back lower char
data[x] = old
time.sleep(1)
# display without upper chars at the end
text = "".join(data)
sys.stdout.write("\r")
sys.stdout.write(text)
sys.stdout.flush()
如果你把多餘的字符在隨後data
結束不具備高版本 - 即。空字符串""
- 然後在for
循環後不需要代碼。
您可以在開始時也放置空字符串以顯示沒有上字符的第一個文本。
import sys
import time
# text with extra chars at the start and at the end
data = ["", "b","u","f","f","e","r","i","n","g", ""]
# display with one upper char
for x in range(len(data)):
# remeber lower char
old = data[x]
# replace with upper char
data[x] = old.upper()
# create full text
text = "".join(data)
# display full text
sys.stdout.write("\r")
sys.stdout.write(text)
sys.stdout.flush()
# put back lower char
data[x] = old
time.sleep(1)
這似乎是你身邊正在尋找什麼http://stackoverflow.com/questions/2122385/dynamic-terminal-printing-with- python – nerdlyist
我改變了下面的腳本,並添加了「\ r」來乞求並修復它,以便它可以做我想要的,謝謝你們的幫助! s ='\ r'+ lowerstr [0:x] + upperstr [x] + lowerstr [x + 1:] +'\ r' – RoNAPC
更新的更改問題!在最後添加修改。現在沒有人會知道代碼中的oryginal代碼和oryginal問題是什麼。 – furas