I am working with a QTableView and trying to retrieve values from the selected row(s). At other times I will be working with mulitiple rows using:

```
self.tableView5.setSelectionMode(QtGui.QAbstractItemView.MultiSelection)

```

The code below works, but only when the first row is selected. However, it shows:

```
identity[row].append(str(self.table_model5.data(index)))
IndexError: list index out of range

```

when another row is clicked.

```
names = []
emails = []
identity = []
data = sorted(set(index.row() for index in self.tableView5.selectionModel().selectedRows()))
for row in data:
    identity.append([])
    for column in range(0,2):
        index = self.table_model5.index(row, column)
        identity[row].append(str(self.table_model5.data(index)))
for item in identity:
    names.append(item[0])
    emails.append(item[1])
for name, recipient in zip(names, emails):
    print(name, recipient)

```