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

Class DictCell
source code

    object --+        
             |        
          Cell --+    
                 |    
         InputCell --+
                     |
UserDict.DictMixin --+
                     |
                    DictCell

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

>>> a.xkeys
[]

>>> a.x['foo'] = 'bar'
>>> a.x
{'foo': 'bar'}

>>> a.xkeys
[]
But if we use a DictCell, this will act like we'd like it to:
>>> class A(cells.Model):
...     x = cells.makecell(value={}, type=DictCell)
...     @cells.fun2cell()
...     def xkeys(self, prev):
...         return self.x.keys()
... 
>>> a = A()
>>> a.x
{}

>>> a.xkeys
[]

>>> a.x['foo'] = 'bar'
>>> a.x
{'foo': 'bar'}

>>> a.xkeys
['foo']
Note that unchanged_if now operates on dictionary values, rather than the dictionary itself.

Instance Methods [hide private]
  __init__(self, owner, name=None, rule=None, value=None, unchanged_if=None)
Initializes an DictCell object.
  setdefault(self, key, value)
  __setitem__(self, key, value)
Sets this cell's value's key's value and begins propogation of the change to the dict, if neccessary.
  __delitem__(self, key)
  __repr__(self)
repr(x)
  get(self, key, default=None)
  __getitem__(self, key)
Gets the value in self.value[key]
  keys(self)
Gets self.value.keys()
  __contains__(self, key)
  __iter__(self)
  iteritems(self)

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__, __setattr__, __str__

Inherited from UserDict.DictMixin: __cmp__, __len__, clear, has_key, items, iterkeys, itervalues, pop, popitem, update, values


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__

setdefault(self, key, value)

source code 
Overrides: UserDict.DictMixin.setdefault

__setitem__(self, key, value)
(Index assignment operator)

source code 
Sets this cell's value's key's value and begins propogation of the change to the dict, if neccessary.
Parameters:
  • key - The value to get out of the cell.value dict
  • value - The value to set this cell's value's key's value to.
Returns:
None

__delitem__(self, key)
(Index deletion operator)

source code 

__repr__(self)
(Representation operator)

source code 
repr(x)
Overrides: object.__repr__
(inherited documentation)

get(self, key, default=None)

source code 
Overrides: UserDict.DictMixin.get

__getitem__(self, key)
(Indexing operator)

source code 
Gets the value in self.value[key]
Parameters:
  • key - lookup
Returns:
value

keys(self)

source code 
Gets self.value.keys()
Returns:
list

__contains__(self, key)
(In operator)

source code 
Overrides: UserDict.DictMixin.__contains__

__iter__(self)

source code 
Overrides: UserDict.DictMixin.__iter__

iteritems(self)

source code 
Overrides: UserDict.DictMixin.iteritems