所以,我在我的最新项目中使用表格来格式化我的数据。但是,它不断给出这个错误,我无法理解它背后的原因。这是代码:
from datetime import date
from tabulate import tabulate
records = []
sno = [0,1]
jades = [0,1]
events = ['0',1]
dates = ['0',1]
for i in range(0, len(jades)):
records.append([sno[i], jades[i], events[i], dates[i]])
print(records)
record = records[-1]
print(record)
print(tabulate(record, headers=["Sno.", "Jades", "Event", "Date"], tablefmt='simple'))
这是输出:
[[0, 0, '0', '0'], [1, 1, 1, 1]]
[1, 1, 1, 1]
Traceback (most recent call last):
File "/home/kartik/Desktop/discord-bot/Rem.py", line 16, in <module>
print(tabulate(record, headers=["Sno.", "Jades", "Event", "Date"], tablefmt='simple'))
File "/home/kartik/.local/lib/python3.8/site-packages/tabulate.py", line 1426, in tabulate
list_of_lists, headers = _normalize_tabular_data(
File "/home/kartik/.local/lib/python3.8/site-packages/tabulate.py", line 1103, in _normalize_tabular_data
rows = list(map(list, rows))
TypeError: 'int' object is not iterable
请注意,我发布的代码只是我发现导致错误的部分。这些行号可能不同。
我试着弄清楚自己,但我唯一能想到的就是这段代码:
record = [records[-1]]
我将最后的记录转换为它自己的列表。
请帮助我了解其背后的原因。我是python的初学者,所以我的问题可能很愚蠢。
先感谢您!