python - 在 python3 中更新 stdout 上的打印字符串

标签 python string format linefeed

我正在尝试使用 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/

相关文章:

python - 如何组合元组列表中的值?

Python/Numpy 分割成子矩阵后重新连接矩阵

PHP 显示来自 MYSQL 的文本

ios - 从相机获取 yuv 平面格式图像 - iOS

MySQL Pivot 准备语句 AS 整数错误

python - django密码重置NoReverseMatch错误

python - 如何在Python中播放视频(cv2)的声音

c++ - c++ 中句子的反向单词,在 Google Code jam 上提问

c# - 删除部分字符串的最佳方法是什么? (C#)

java - toString 方法不将字母大写