码迷,mamicode.com
首页 > 编程语言 > 详细

python curses库

时间:2015-06-21 00:53:14      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:python curses 多行不换行 newline

今天论坛里有人问怎么实现类似linux top那样输出的效果. 


单行不换行这个知道.但是这么多行一直输出还真没折腾过.


搜索发现 curses 可以实现这个效果.


一个把当前 ps aux 部分进程显示出来的脚本

#!/usr/bin/env python

import curses
import os

ch = 0

while ch != ord("q"):
    screen = curses.initscr()
    screen.clear()
#    screen.border(0)
    
    for i in range(100):
        try:
            screen.addstr(i+1,0,os.popen("ps aux |awk ‘NR==%s‘" % i).read(),curses.A_NORMAL)
            screen.refresh()
        except:
            pass

    ch = screen.getch()
    
curses.endwin()



详细参考:

docs.python.org/2/howto/curses.html

tuxradar.com/content/code-project-build-ncurses-ui-python

stackoverflow.com

python curses库

标签:python curses 多行不换行 newline

原文地址:http://abian.blog.51cto.com/751059/1663906

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!