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

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

问题描述

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

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

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

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

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?

推荐答案

由于某种原因,当我在Google搜索中包含"docutils"时,偶然发现了

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天全站免登陆