Handle either a list or single integer as an argument

后端 未结 6 880
萌比男神i
萌比男神i 2020-12-05 01:59

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 ha

6条回答
  •  感动是毒
    2020-12-05 02:24

    I would do just this:

    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)
    

    and expect that the argument will always be a list - even if its just a list of one element.

    Remember:

    It is easier to ask for forgiveness than permission.

提交回复
热议问题