ConstructableDict

class pysit.util.util.ConstructableDict(func)[source]

Bases: dict

A ConstructableDict returns the value mapped to a key. If that key does not exist, a function which creates the desired value at the key is called with the key as the argument.

Examples

>>> def buildfun(key):
...     def myprint(x): print key*x
...     return myprint
>>> a = ConstructableDict()
>>> a
{}
>>> a[5]
<function myprint>
>>> a[6](7)
42