def select_rows(view, row_indices, command=QItemSelectionModel.ClearAndSelect):
 selmodel = view.selectionModel()
 model = view.model()
 selection = QItemSelection()
 for row in row_indices:
  index = model.index(row, 0)
  selection.select(index, index)
 selmodel.select(selection, (command | QItemSelectionModel.Rows))

def select_rows ( view , row_indices , command = QItemSelectionModel . ClearAndSelect ) : selmodel = view . selectionModel ( ) model = view . model ( ) selection = QItemSelection ( ) for row in row_indices : index = model . index ( row , 0 ) selection . select ( index , index ) selmodel . select ( selection , ( command | QItemSelectionModel . Rows ) )
select rows in view .