import sys
import time
fewds = ["raspberry", "orange", "pineapple", "fig", "honeysuckle"]
for f in fewds:
sys.stdout.write(f+"\r")
sys.stdout.flush()
time.sleep(0.5)
Return the string left justified in a
string of length width. Padding is done using the specified fillchar
(default is an ASCII space). The original string is returned if width
is less than or equal to len(s).
所以,你的代码是:
import sys
import time
fewds = ["raspberry", "orange", "pineapple", "fig", "honeysuckle"]
last_length = 0
for f in fewds:
sys.stdout.write(f.ljust(last_length) + "\r")
sys.stdout.flush()
time.sleep(0.5)
last_length = len(f)
您可以跟踪打印的最后一行的长度,并使用str.ljust为下一行添加必要的空格,以便完全覆盖上一行
所以,你的代码是:
相关问题 更多 >
编程相关推荐