Returns an item, row or slice from the matrix. For Datasheet[i], returns the row at the given index. For Datasheet[i,j], returns the value in row i and column j.
(self, index)
| 1724 | raise TypeError, "Datasheet indices must be int or tuple" |
| 1725 | |
| 1726 | def __getitem__(self, index): |
| 1727 | """ Returns an item, row or slice from the matrix. |
| 1728 | For Datasheet[i], returns the row at the given index. |
| 1729 | For Datasheet[i,j], returns the value in row i and column j. |
| 1730 | """ |
| 1731 | if isinstance(index, (int, slice)): |
| 1732 | # Datasheet[i] => row i. |
| 1733 | return list.__getitem__(self, index) |
| 1734 | if isinstance(index, tuple): |
| 1735 | i, j = index |
| 1736 | # Datasheet[i,j] => item from column j in row i. |
| 1737 | # Datasheet[i,j1:j2] => columns j1-j2 from row i. |
| 1738 | if not isinstance(i, slice): |
| 1739 | return list.__getitem__(self, i)[j] |
| 1740 | # Datasheet[i1:i2,j] => column j from rows i1-i2. |
| 1741 | if not isinstance(j, slice): |
| 1742 | return [row[j] for row in list.__getitem__(self, i)] |
| 1743 | # Datasheet[i1:i2,j1:j2] => Datasheet with columns j1-j2 from rows i1-i2. |
| 1744 | return Datasheet( |
| 1745 | rows = (row[j] for row in list.__getitem__(self, i)), |
| 1746 | fields = self.fields and self.fields[j] or self.fields) |
| 1747 | raise TypeError, "Datasheet indices must be int, tuple or slice" |
| 1748 | |
| 1749 | def __getslice__(self, i, j): |
| 1750 | # Datasheet[i1:i2] => Datasheet with rows i1-i2. |
nothing calls this directly
no test coverage detected