MCPcopy Index your code
hub / github.com/clips/pattern / __getitem__

Method __getitem__

pattern/db/__init__.py:1726–1747  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers

nothing calls this directly

Calls 2

DatasheetClass · 0.85
__getitem__Method · 0.45

Tested by

no test coverage detected