此之前已经被要求(例如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