【发布时间】:2019-08-13 23:06:14
【问题描述】:
我想将beautifultable 的行转换为列表的元素,同时排除标题,例如:
[['A',2,4], ['B',2,5], ['C',2,1]]
【问题讨论】:
标签: python python-beautifultable
我想将beautifultable 的行转换为列表的元素,同时排除标题,例如:
[['A',2,4], ['B',2,5], ['C',2,1]]
【问题讨论】:
标签: python python-beautifultable
打电话就行了
list(map(list, table))
完整代码:
from beautifultable import BeautifulTable
table = BeautifulTable()
table.column_headers = ["c1", "c2", "c3"]
table.append_row(['A', 2, 4])
table.append_row(['B', 2, 5])
table.append_row(['C', 2, 6])
print(table)
# it will print
# +----+----+----+
# | c1 | c2 | c3 |
# +----+----+----+
# | A | 2 | 4 |
# +----+----+----+
# | B | 2 | 5 |
# +----+----+----+
# | C | 2 | 6 |
# +----+----+----+
li = list(map(list, table))
print(li)
# it will print
# [['A', 2, 4], ['B', 2, 5], ['C', 2, 6]]
【讨论】:
如果您尝试获取行,Beautifultable 会给出以下结果:
list([r for r in table])
=> [RowData<'A',2,4>, RowData<'B',2,5>, RowData<'C',2,1>]
将其转换为形式:[['A',2,4], ['B',2,5], ['C',2,1]]
用途:
list([list(r) for r in table])
【讨论】: