Package cells :: Module cell :: Class ListCell
[hide private]
[frames] | no frames]

Class ListCell
source code

object --+        
         |        
      Cell --+    
             |    
     InputCell --+
                 |
                ListCell

A input cell whose value is initialized to []. An ordinary InputCell doesn't act like we'd like it to in this case:
>>> import cells
>>> class A(cells.Model):
...     x = cells.makecell(value=[])
...     @cells.fun2cell()
...     def xlen(self, prev):
...         return len(self.x)
... 
>>> a = A()
>>> a.x
[]

>>> a.xlen
0

>>> a.x.append("foo")
>>> a.x
['foo']

>>> a.xlen
0
But if we specify a ListCell, it should work as we expect it:
>>> import cells
>>> class A(cells.Model):
...     x = cells.makecell(value=[])
...     @cells.fun2cell()
...     def xlen(self, prev):
...         return len(self.x)
... 
>>> a = A()
>>> a.x
[]

>>> a.xlen
0

>>> a.x.append("foo")
>>> a.x
['foo']

>>> a.xlen
1
Note that unchanged_if acts on list elements rather than the entire value.

Instance Methods [hide private]
  __init__(self, owner, name=None, rule=None, value=None, unchanged_if=None)
Initializes an DictCell object.
  _onchanges(self)
  _pregets(self)
  _should_defer(self, name, argtuple)
  count(self, v)
  index(self, v, start=None, stop=None)
  __getitem__(self, k)
  __iter__(self)
  __len__(self)
  pop(self, index=None)
Warning: ListCell.pop() does not act quite like you may expect it in certain circumstances.
  _make_listfun(name)
  append(self, *args, **kwargs)
  extend(self, *args, **kwargs)
  insert(self, *args, **kwargs)
  remove(self, *args, **kwargs)
  reverse(self, *args, **kwargs)
  sort(self, *args, **kwargs)
  __add__(self, *args, **kwargs)
  __iadd__(self, *args, **kwargs)
  __mul__(self, *args, **kwargs)
  __rmul__(self, *args, **kwargs)
  __imul__(self, *args, **kwargs)
  __setitem__(self, *args, **kwargs)
  __delitem__(self, *args, **kwargs)

Inherited from InputCell: run

Inherited from Cell: add_called_by, add_calls, called_by_list, calls_list, changed, getvalue, propogate, propogation_list, remove_called_bys, remove_cb, reset_calls, set, updatecell

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__


Class Variables [hide private]

Inherited from object: __class__


Instance Variables [hide private]

Inherited from Cell: called_by, calls, synapse_space


Method Details [hide private]

__init__(self, owner, name=None, rule=None, value=None, unchanged_if=None)
(Constructor)

source code 
Initializes an DictCell object. You may not pass a rule.
Parameters:
  • name - This cell's name. When using a Cell with Models, this parameter is assigned automatically.
  • value - Define a value for this cell. This must be a dictionary.
  • unchanged_if - Sets a function to determine if the dictionary's value has changed. The signature for the passed function is f(old, new) -> bool.
Returns:
None

Raises:
  • InputCellRunError - If rule is passed as a parameter
Overrides: InputCell.__init__

_onchanges(self)

source code 

_pregets(self)

source code 

_should_defer(self, name, argtuple)

source code 

count(self, v)

source code 

index(self, v, start=None, stop=None)

source code 

__getitem__(self, k)
(Indexing operator)

source code 

__iter__(self)

source code 

__len__(self)
(Length operator)

source code 

pop(self, index=None)

source code 
Warning: ListCell.pop() does not act quite like you may expect it in certain circumstances. If a pop occurs during a propogation, the value will be returned, but the list will not be altered until the end of the propogation (thus ensuring all cells "see" the same value of this cell during the DP).

_make_listfun(name)

source code 

append(self, *args, **kwargs)

source code 

extend(self, *args, **kwargs)

source code 

insert(self, *args, **kwargs)

source code 

remove(self, *args, **kwargs)

source code 

reverse(self, *args, **kwargs)

source code 

sort(self, *args, **kwargs)

source code 

__add__(self, *args, **kwargs)
(Addition operator)

source code 

__iadd__(self, *args, **kwargs)

source code 

__mul__(self, *args, **kwargs)

source code 

__rmul__(self, *args, **kwargs)

source code 

__imul__(self, *args, **kwargs)

source code 

__setitem__(self, *args, **kwargs)
(Index assignment operator)

source code 

__delitem__(self, *args, **kwargs)
(Index deletion operator)

source code