如何使用 Python 漂亮地打印 ASCII 表? [英] How can I pretty-print ASCII tables with Python?

查看:46
本文介绍了如何使用 Python 漂亮地打印 ASCII 表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来漂亮地打印这样的表格:

========================|第 1 列 |第 2 栏 |========================|值 1 |值2 ||值3 |值4 |========================

我找到了 asciitable 库,但它没有做边框等. 我不需要任何复杂的数据项格式,它们只是字符串.我确实需要它来自动调整列大小.

是否存在其他库或方法,还是我需要花几分钟时间编写自己的库或方法?

解决方案

出于某种原因,当我在 google 搜索中包含docutils"时,我偶然发现了 texttable,这似乎是我要找的.

I'm looking for a way to pretty-print tables like this:

=======================
| column 1 | column 2 |
=======================
| value1   | value2   |
| value3   | value4   |
=======================

I've found the asciitable library but it doesn't do the borders, etc. I don't need any complex formatting of data items, they're just strings. I do need it to auto-size columns.

Do other libraries or methods exist, or do I need to spend a few minutes writing my own?

解决方案

For some reason when I included 'docutils' in my google searches I stumbled across texttable, which seems to be what I'm looking for.

这篇关于如何使用 Python 漂亮地打印 ASCII 表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆