若refresh前一行沒有辦法,因為dos環境只有cls清除全畫面指令能用
若要在單行顯示a:xx b:yy不斷刷新就可以,範例如下:
from time import sleep
print('Press Ctrl-C to quit.')
a, b = 1,2
try:
while True:
tmpStr = 'a: ' + str(a).rjust(4)+ ' b: ' + str(b).rjust(4)
print(tmpStr, end='')
print('\b' * len(tmpStr), end='', flush=True)
a=a+2
b=b+2
sleep(0.5) #暫停秒數
except KeyboardInterrupt:
print('\nDone.')