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

Class Datasheet

pattern/db/__init__.py:1649–1888  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1647#--- DATASHEET -------------------------------------------------------------------------------------
1648
1649class Datasheet(CSV):
1650
1651 def __init__(self, rows=[], fields=None, **kwargs):
1652 """ A matrix of rows and columns, where each row and column can be retrieved as a list.
1653 Values can be any kind of Python object.
1654 """
1655 # NumPy array, convert to list of int/float/str/bool.
1656 if rows.__class__.__name__ == "ndarray":
1657 rows = rows.tolist()
1658 self.__dict__["_rows"] = DatasheetRows(self)
1659 self.__dict__["_columns"] = DatasheetColumns(self)
1660 self.__dict__["_m"] = 0 # Number of columns per row, see Datasheet.insert().
1661 CSV.__init__(self, rows, fields, **kwargs)
1662
1663 def _get_rows(self):
1664 return self._rows
1665 def _set_rows(self, rows):
1666 # Datasheet.rows property can't be set, except in special case Datasheet.rows += row.
1667 if isinstance(rows, DatasheetRows) and rows._datasheet == self:
1668 self._rows = rows; return
1669 raise AttributeError, "can't set attribute"
1670 rows = property(_get_rows, _set_rows)
1671
1672 def _get_columns(self):
1673 return self._columns
1674 def _set_columns(self, columns):
1675 # Datasheet.columns property can't be set, except in special case Datasheet.columns += column.
1676 if isinstance(columns, DatasheetColumns) and columns._datasheet == self:
1677 self._columns = columns; return
1678 raise AttributeError, "can't set attribute"
1679 columns = cols = property(_get_columns, _set_columns)
1680
1681 def __getattr__(self, k):
1682 """ Columns can be retrieved by field name, e.g., Datasheet.date.
1683 """
1684 #print "Datasheet.__getattr__", k
1685 if k in self.__dict__:
1686 return self.__dict__[k]
1687 for i, f in enumerate(f[0] for f in self.__dict__["fields"] or []):
1688 if f == k:
1689 return self.__dict__["_columns"][i]
1690 raise AttributeError, "'Datasheet' object has no attribute '%s'" % k
1691
1692 def __setattr__(self, k, v):
1693 """ Columns can be set by field name, e.g., Datasheet.date = [...].
1694 """
1695 #print "Datasheet.__setattr__", k
1696 if k in self.__dict__:
1697 self.__dict__[k] = v
1698 return
1699 if k == "rows":
1700 self._set_rows(v)
1701 return
1702 if k == "columns":
1703 self._set_columns(v)
1704 return
1705 if k == "headers":
1706 self._set_headers(v)

Callers 13

08-web.pyFile · 0.90
04-twitter.pyFile · 0.90
11-facebook.pyFile · 0.90
02-datasheet.pyFile · 0.90
datasheetMethod · 0.85
__getitem__Method · 0.85
__getslice__Method · 0.85
__radd__Method · 0.85
groupMethod · 0.85
sliceMethod · 0.85
copyMethod · 0.85
flipFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…