如何做部分运输退货

2024-04-20 13:40:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我想替换Python脚本的cmd输出,而不覆盖行的前三个字符。我的意思是:

我想要什么:

>>>ID1 downloading
>>>ID1 converting
>>>ID1 finished

使用/r

>>>ID0 downloading
>>>converting
>>>finished

Tags: 脚本cmd字符finisheddownloadingid1convertingid0
2条回答

这根本不是一个Python问题,而是一个标准的输出问题。你知道吗

标准输出不是这样工作的。最简单的就是重写“ID1”。你知道吗

否则,您将需要转向更高级的东西:或者是特定于控制台的格式化命令(比如ANSI),或者是类似curses的库。你知道吗

试试这个。但这在空闲时可能不起作用。你知道吗

from time import sleep
from sys import stdout
stdout.write("\r%s" % "ID1 downloading")
stdout.flush()
sleep(1)
stdout.write("\r%s" % "ID1 converting ")
stdout.flush()
sleep(1)
stdout.write("\r%s" % "ID1 done       ")
stdout.write("\r  \r\n") # clean up

相关问题 更多 >