作者:动感奥13 | 来源:互联网 | 2023-08-22 14:11
Afunctionshouldselectrowsinatablebasedontherowname(column2inthiscase).Itshouldbe
A function should select rows in a table based on the row name (column 2 in this case). It should be able to take either a single name or a list of names as arguments and handle them correctly.
函数应根据行名称选择表中的行(在本例中为第2列)。它应该能够将单个名称或名称列表作为参数并正确处理它们。
This is what I have now, but ideally there wouldn't be this duplicated code and something like exceptions would be used intelligently to choose the right way to handle the input argument:
这就是我现在所拥有的,但理想情况下不会出现这种重复的代码,并且可以智能地使用类似异常的方法来选择处理输入参数的正确方法:
def select_rows(to_select):
# For a list
for row in range(0, table.numRows()):
if _table.item(row, 1).text() in to_select:
table.selectRow(row)
# For a single integer
for row in range(0, table.numRows()):
if _table.item(row, 1).text() == to_select:
table.selectRow(row)
4 个解决方案