Actually I agree with Andrew Hare's answer, just pass a list with a single element.
But if you really must accept a non-list, how about just turning it into a list in that case?
def select_rows(to_select):
if type(to_select) is not list: to_select = [ to_select ]
for row in range(0, table.numRows()):
if _table.item(row, 1).text() in to_select:
table.selectRow(row)
The performance penalty for doing 'in' on a single-item list isn't likely to be high :-)
But that does point out one other thing you might want to consider doing if your 'to_select' list may be long: consider casting it to a set so that lookups are more efficient.
def select_rows(to_select):
if type(to_select) is list: to_select = set( to_select )
elif type(to_select) is not set: to_select = set( [to_select] )
for row in range(0, table.numRows()):
if _table.item(row, 1).text() in to_select:
table.selectRow(row)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…