如何在Windows命令行的当前行上覆盖/打印? [英] How can I overwrite/print over the current line in Windows command line?
本文介绍了如何在Windows命令行的当前行上覆盖/打印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Unix上,我可以使用\r
(回车)或\b
(退格键)覆盖shell中的当前行(在已经可见的文本上打印).
On Unix, I can either use \r
(carriage return) or \b
(backspace) to overwrite the current line (print over text already visible) in the shell.
我可以在Windows命令行中使用Python脚本实现相同的效果吗?
Can I achieve the same effect in a Windows command line from a Python script?
我尝试了curses模块,但Windows上似乎没有该模块.
I tried the curses module but it doesn't seem to be available on 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()
这篇关于如何在Windows命令行的当前行上覆盖/打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文