Python文本选项卡

2024-04-28 23:59:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用texttable为练习构建一个表。你知道吗

tab.add_row(row) = ["Match1", Team1_matches[1], Team2_matches[1], max(Team1_matches[1],Team2_matches[1])]

我明白了:

  tab.add_rows(row) = ["Match1", Team1_matches[1], Team2_matches[1]]
SyntaxError: can't assign to function call

Tags: toaddfunctiontabcanmaxrowsrow
1条回答
网友
1楼 · 发布于 2024-04-28 23:59:34

您将元素列表分配给了tab.add_row(row),这就是为什么您得到了SyntaxError

正确的使用方法是:

# create a list with the elements and assign it to row
row = ["Match1", Team1_matches[1], Team2_matches[1], max(Team1_matches[1],Team2_matches[1])]
# insert a row into table by invoking add_row() of the TextTable object tab.
tab.add_row(row)

相关问题 更多 >