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
新しい変更質問!最後に変更を追加します。今では誰も、コード内でオリジナルコードと奇妙な問題が何であったかは分かりません。 – furas