作者rexyeah (ccccccc)
看板Python
标题Re: [问题] 如何持续更新print内容
时间Sat Sep 22 21:49:46 2018
有找到一个比\r好用
curses (
https://goo.gl/ivB5YG)
import curses
import sys
import time
from datetime import datetime
import random
def main(stdscr):
for i in range(10):
stdscr.clear()
stdscr.addstr("CurrentTime: %s\n" % datetime.now())
stdscr.addstr("Num: %d\n" % (i+1))
stdscr.addstr("Choice: %s" % ['a', 'b', 'c', 'd'][random.randint(0, 3)])
time.sleep(0.5)
stdscr.refresh()
main(curses.initscr())
※ 引述《renshin (阿信)》之铭言:
: 各位大大好
: 想请教如何持续更新显示内容
: 目前google查到都只能处理一行
: 若我的内容有多行以上可以如何达到这个功能呢?
: ex:
: 现在时间:A
: 人数:B
: 其他:C
: 以上是显示范例
: 希望能在print的时候永远只显示3行,只更新ABC变数
: 还请大大们教学,感恩
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 1.163.214.81
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1537624189.A.F5D.html
1F:→ renshin: 请问这是for python2.x吗?我在3跑有error 09/25 10:58
2F:→ renshin: 我再尝试看看,感谢分享 09/25 10:59
3F:→ rexyeah: 我是2.7 on Ubuntu std lib. Windows要安装curses mod. 09/25 12:04