使用python2.7,我正在尝试打印到屏幕表格数据。这大致就是我的代码:for i in mylist: print "{}\t|{}\t|".format (i, f(i))问题是,取决于长度i或f(i)数据将不会对齐。这就是我得到的:|foo |bar ||foobo |foobar |我想得到什么:|foo |bar ||foobo |foobar |是否有允许执行此操作的模块?
3 回答

慕丝7291255
TA贡献1859条经验 获得超6个赞
为了使表格更美观,请使用表格模块:
这里举一个例子:
>>> from tabulate import tabulate
>>> table = [["Sun",696000,1989100000],["Earth",6371,5973.6],
... ["Moon",1737,73.5],["Mars",3390,641.85]]
>>> print tabulate(table)
----- ------ -------------
Sun 696000 1.9891e+09
Earth 6371 5973.6
Moon 1737 73.5
Mars 3390 641.85
----- ------ -------------
添加回答
举报
0/150
提交
取消