【发布时间】:2020-09-17 21:10:24
【问题描述】:
我有一个问题,我想删除一些打印,但它被完全忽略了,并且打印了几行。对于这些解决方案,我一直使用\r。有没有办法绕过这种情况? (我现在使用的是 Mac OS,但保证很快就会切换到 Windows。)@Feodoran 告诉我,\r 仅适用于 Linux 计算机,这是一个问题。代码如下:
print ('virus_prevention.fix.virus.|attempt_enter')
time.sleep(2)
for i in range(1):
sys.stdout.write(str(i)+'\r')
print ('virus_prevention.fix.virus|.attempt_enter')
time.sleep(0.1)
for i in range(1):
sys.stdout.write(str(i)+'\r')
输出如下:
virus_prevention.fix.virus.|attempt_enter
0
virus_prevention.fix.virus|.attempt_enter
0
我尝试过sys.stdout.write 而不是print,但似乎没有任何改变。我不确定在这种情况下该怎么做,但如果有人能给我一些建议,请做。它正在删除完全不起作用的打印行。
【问题讨论】:
-
你想达到什么目的?
for i in range(1):只迭代一次,与它根本不存在是一样的。你在哪个终端调用你的 python 脚本(即它的显示方式取决于正在使用的终端和在哪个操作系统下(OS X 使用 \r 进行换行) -
其实你是对的。但是我现在还不清楚如何删除打印。
-
这能回答你的问题吗? Terminal - How to overwrite many lines?MacOS 有解决方案,或许有帮助。
-
不完全。它只是出现一个空白屏幕。第二个可能有效。
-
不,语法无效。
标签: python python-3.x