利用字符串的"\r"回到行頭 再利用sys.stdout打印就能夠出來在原地打印的效果了.代碼以下:python
# -*- coding: utf-8 -* import sys import time for i in range(10): # 像console中打印回車和i,下次打印的時候依舊是先打印回車(回到行頭再打印i) sys.stdout.write("\r{}".format(i)) time.sleep(1) # 刷新緩衝區 sys.stdout.flush()
結果: 0-9都在原地打印app
C:\Python27\python.exe D:/Eleme/automation_appium/tt.py 9 Process finished with exit code 0