| Home | Trees | Index | Help |
|
|---|
|
|
object --+
|
Model
__init__-time. Cells may be altered at runtime by
passing attrname=value, or attrname=hash to the
constructor.
|
|||
| __metaclass__ | |||
|
|||
|
__init__(self,
*args,
**kwargs)
__init__(self, [<attrname>=<value, rule or dict>], ...) -> None |
|||
|
__setattr__(self,
key,
value)
Per KT's spec, Models may not set non-cell attributes after __init__. |
|||
| _buildcell(self, name, *args, **kwargs) | |||
|
_run_observers(self,
attribute)
Runs each observer in turn. |
|||
|
Inherited from |
|||
|
|||
|
observer(attrib=None,
oldvalue=None,
newvalue=None)
A classmethod to add an observer attribute to a Model. |
|||
|
|||
| _initialized | |||
| _noncells | |||
| _observernames | |||
|
Inherited from |
|||
|
|||
| model_name | A cell holding The name of this Model. | ||
| model_value | A cell holding the value of this Model. | ||
| parent | A cell for Family graph traversal. |
||
|
|||
__init__(self, [<attrname>=<value, rule or dict>], ...) -> None Initialize a Model with optional overrides. By passing a parameter with the same name as a cell attribute, you may override that cell attribute. For example:>>> class A(cells.Model): ... x = cells.makecell(value=1) ... >>> a1 = A() >>> a1.x 1 >>> a2 = A(x="blah") >>> a2.x 'blah'This override can be arbitrarily complex; for instance, you can make a RuleCell into a ValueCell, change a attribute's celltype ... In short, anything you can do at Model defintion time you can alter at instantiation time: >>> class B(cells.Model): ... x = cells.makecell(rule=lambda s,p: 3 * s.y) ... y = cells.makecell(value=2) ... >>> b = B() >>> b.x 6 >>> b.y = 1 >>> b.x 3 >>> b = B(y=10) >>> b.x 30 >>> b.y 10 >>> b = B(x={'celltype': cells.RuleThenInputCell}) >>> b.x 6 >>> b.y 2 >>> b.x = 5 >>> b.x 5 >>> b.y = 1 >>> b.x 5
|
|
|
|
>>> import cells >>> class A(cells.Model): ... x = cells.makecell(value=4) ... >>> @A.observer(attrib="x", newvalue=lambda a: a % 2) ... def odd_x_obs(model): ... print "New value of x is odd!" ... >>> a = A() >>> a.x 4 >>> a.x = 5 New value of x is odd! >>> a.x = 42 >>> a.x = 11 New value of x is odd!
|
|
|||
_initialized
|
_noncells
|
_observernames
|
|
|||
model_nameA cell holding The name of this Model. By default, None.
|
model_valueA cell holding the value of this Model. By default, None.
|
parentA cell forFamily graph traversal. By default, None.
|
| Home | Trees | Index | Help |
|
|---|
| Generated by Epydoc 3.0alpha2 on Sun Aug 20 15:38:10 2006 | http://epydoc.sf.net |