-2

我是使用curses lib的新手。我想制作一个 python 程序(在 DOS 终端中运行),它可以将光标返回到当前行的开头,从而允许后续输出覆盖之前在那里写入的内容。我试图从 python 调用一个 shellscript 来做到这一点,但我相信它可能存在更好的方法来做到这一点。

4

1 回答 1

0

如果您只想重写当前行,只需打印一个返回字符“\r”。例如,这将打印“ABCdef”:

# print 'abcdef' then backup to start of line, then print 'ABC'
# (then print the normal cr/lf that 'print' always does)
print "abcdef\rABC"

(知道您可以通过用尾随逗号结束打印来抑制 cr/lf 也很有帮助...)。

于 2012-06-04T17:20:53.880 回答