V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
szyp
V2EX  ›  Python

Python 有没有什么好用的命令行图形库 ?

  •  
  •   szyp ·
    runningzyp · 2020-05-23 15:06:45 +08:00 · 3588 次点击
    这是一个创建于 1405 天前的主题,其中的信息可能已经有所发展或是发生改变。

    可能我的描述有点让人摸不着头脑 ,实际上我的需求很简单,就是在命令行打印出下面或者类似的图形,主要是为了日志好看😜

    +-------------------------+--------------------------+-------------------------+
    | Header Col 1            | Header Col 2             | Header Col3             |
    +=========================+==========================+=========================+
    | This is the first value | This is the second value | This is the third value |
    +-------------------------+--------------------------+-------------------------+
    | Red                     | Blue                     | Green                   |
    +-------------------------+--------------------------+-------------------------+
    | 42                      | 10                       | 1                       |
    +-------------------------+--------------------------+-------------------------+
    

    一般情况下,我都是通过 print("+---------------------------+")来做到上面的效果的,但是每次使用都这么麻烦,还要敲那么多无用字符,所以就想问问有没有专门做这个的库:P

    12 条回复    2020-05-25 23:50:46 +08:00
    renmu123
        1
    renmu123  
       2020-05-23 15:13:38 +08:00 via Android   ❤️ 1
    prettytable
    Sylv
        2
    Sylv  
       2020-05-23 15:19:25 +08:00 via iPhone   ❤️ 1
    用过 tabulate,还不错:
    https://github.com/astanin/python-tabulate
    ClericPy
        3
    ClericPy  
       2020-05-23 15:31:18 +08:00
    上面提过的 terminal table 工具都挺不错的, 我想顺路问下, 有没有带刷新的 panel 版本的表格啊... 类似 htop 那种不断刷新的控制台的
    Liyiw
        4
    Liyiw  
       2020-05-24 00:44:03 +08:00
    有人说说 prettytable 和 tabulate 哪个好用吗
    ETCartman
        5
    ETCartman  
       2020-05-24 01:34:41 +08:00 via iPhone   ❤️ 2
    https://github.com/willmcgugan/rich 最近在用,感觉还不错。
    szyp
        6
    szyp  
    OP
       2020-05-24 07:18:02 +08:00 via iPhone
    @renmu123 谢谢,去试试
    owwlo
        7
    owwlo  
       2020-05-24 08:56:56 +08:00
    @ETCartman rich 这个真的好酷!之前做东西有类似需求的时候竟然没有查到!

    因为自己的小项目大部分是命令行的,后来把一些公共的部分提取出来做了这个 https://github.com/owwlo/PyTerminalCommander

    今天花了点时间加了 overwrite output 的功能: https://asciinema.org/a/333295,楼主如果觉得有趣可以试试 ;)
    szyp
        8
    szyp  
    OP
       2020-05-24 21:56:14 +08:00
    @owwlo 好的,去看看
    @ETCartman 确实挺好用,logger 更好看了
    songdg
        9
    songdg  
       2020-05-25 11:50:47 +08:00
    @ETCartman 非常好用,就是教程太简短了,不知有没有详细点的教程。
    ETCartman
        10
    ETCartman  
       2020-05-25 12:31:41 +08:00
    songdg
        11
    songdg  
       2020-05-25 23:48:26 +08:00
    @ETCartman 谢谢帮助,试了一下感觉对中文支持不太好,总是对不齐。
    songdg
        12
    songdg  
       2020-05-25 23:50:46 +08:00
    @renmu123 不知怎么的 prettytable 的 Showing title 好像用不了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1171 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 18:28 · PVG 02:28 · LAX 11:28 · JFK 14:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.