如何在python中覆盖以前的"print"值?
print "hello"
print "dude"
print "bye"
Run Code Online (Sandbox Code Playgroud)
它将输出:
hello
dude
bye
Run Code Online (Sandbox Code Playgroud)
但我想覆盖这个价值.
在这种情况下,输出将是:
bye
Run Code Online (Sandbox Code Playgroud)
检查这个curses库,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')
Run Code Online (Sandbox Code Playgroud)
运行 python x.py
归档时间: |
|
查看次数: |
1744 次 |
最近记录: |