2024-03-29 13:09:39 发布
网友
如何覆盖python中以前的“print”值?在
print "hello" print "dude" print "bye"
它将输出:
但是我想覆盖这个值。在
在这种情况下,输出将是:
bye
选中这个curses library,curses库为基于文本的终端提供了一个独立于终端的屏幕绘制和键盘处理工具。例如:
x.py:
from curses import wrapper def main(stdscr): stdscr.addstr(1, 0, 'Program is running..') # Clear screen stdscr.clear() # clear above line. stdscr.addstr(1, 0, 'hello') stdscr.addstr(2, 0, 'dude') stdscr.addstr(3, 0, 'Press Key to exit: ') stdscr.refresh() stdscr.getkey() wrapper(main) print('bye')
运行它python x.py
python x.py
import os print "hello" print "dude" if <your condition to bye print > os.system('clear') print "bye"
您可以使用sys.stdout.write避免在每次调用时print打印的换行符,并使用回车符{}返回行的开头:
sys.stdout.write
print
import sys sys.stdout.write("hello") sys.stdout.write("\rdude") sys.stdout.write("\rbye")
要覆盖上一句的所有字符,您可能需要添加一些空格。在
在以print为函数的python3或python2上,可以使用end参数:
end
请注意,它在空闲状态下无法工作。在
选中这个curses library,curses库为基于文本的终端提供了一个独立于终端的屏幕绘制和键盘处理工具。例如:
x.py:
运行它
python x.py
您可以使用}返回行的开头:
sys.stdout.write
避免在每次调用时print
打印的换行符,并使用回车符{要覆盖上一句的所有字符,您可能需要添加一些空格。在
在以
^{pr2}$print
为函数的python3或python2上,可以使用end
参数:请注意,它在空闲状态下无法工作。在
相关问题 更多 >
编程相关推荐