我正在尝试使用 python 和格式化字符串更新打印到标准输出的行。该行正在打印,但在每次循环时都会在同一行上打印,位于上一个打印的更新旁边。
item = ("{}{}{}{}".format(totalAllScraped,
str(" profiles scraped "),
(len(sortedurls)),
str(" filtered profiles saved.")))
print(item, sep='', end='', flush=True)
我想将该行打印到标准输出,并且循环的每次迭代,前一行都会被下一行覆盖。
最佳答案
import sys
stuff = ("{}{}{}{}".format(totalAllScraped, str(" profiles scraped "), (len(sortedurls)), str(" filtered profiles saved.")))
sys.stdout.write("\r" + stuff)
sys.stdout.flush()
无论如何,这已经成功了,谢谢
关于python - 在 python3 中更新 stdout 上的打印字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46900610/