此之前已經被要求(例如a,b等),但我不能讓它在IPython中控制檯工作。 我只是想在同一行上反覆打印一些文本,而不是連續文本,而是替換前一個文本。 這是我的代碼:打印在IPython的控制檯同一地點
import time
try:
while True:
s = "I want this always on the same line. "
print(s, end="\r", flush=True)
time.sleep(0.5)
except KeyboardInterrupt:
pass
,這裏是我所得到的在IPython的控制檯:
我使用的PC和Spyder的蟒蛇分佈,與Python 3代碼在蟒蛇終端,但我需要打印出一些圖像,所以我需要IPython。我也嘗試使用end=""
或在print()
聲明(即使這是Python 2)後添加逗號,但無濟於事。
'打印( 「你好」,結束= 「\ r」)'我的控制檯(終端)上正常工作。 – ZdaR
我得到 「hellohellohellohellohellohellohellohellohellohellohello」 ... – Zep
嘗試運行它在終端,'python3 run.py' @Zep – ZdaR