在 Unix 上,我可以使用 \r
(回车)或 \b
(退格)覆盖当前行(打印已经可见的文本)外壳。
我可以通过 Python 脚本在 Windows 命令行中实现相同的效果吗?
我尝试了 curses 模块,但它似乎在 Windows 上不可用。
最佳答案
是的:
import sys
import time
def restart_line():
sys.stdout.write('\r')
sys.stdout.flush()
sys.stdout.write('some data')
sys.stdout.flush()
time.sleep(2) # wait 2 seconds...
restart_line()
sys.stdout.write('other different data')
sys.stdout.flush()
关于python - 如何在 Windows 命令行中覆盖/打印当前行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/465348/