makecell(rule=None,
value=None,
unchanged_if=None,
celltype=None)
| source code |
Creates a new cell attribute in a Model. This
attribute may be accessed as one would access a non-cell attribute, and
autovivifies itself in the instance upon first access (in Model.__init__).
-
- Parameters:
rule - Define a rule which backs this cell. You must only define one
of rule or value. Lacking
celltype, this creates a RuleCell.
This must be passed a callable with the signature f(self,
prev) -> value, where self is the model
instance the cell is in and prev is the cell's
out-of-date value.
value - Define a value for this cell. You must only define one of
rule or value. Lacking
celltype, this creates an InputCell.
unchanged_if - Sets a function to determine if a cell's value has changed.
For example,
>>> class A(cells.Model):
... x = cells.makecell(value=1,
... unchanged_if=lambda n,o: abs(n - o) > 5)
... y = cells.makecell(rule=lambda s,p: s.x * 2)
...
>>> a = A()
>>> a.x
1
>>> a.y
2
>>> a.x = 3
>>> a.x
3
>>> a.y
6
>>> a.x = 90
>>> a.x
3
>>> a.y
6
The signature for the passed function is f(old, new)
-> bool.
celltype - Set the cell type to generate. You must pass rule
or value correctly. Refer to cells.cell for
available types.
- Returns:
CellAttr
|