pyart.lazydict.LazyLoadDict#

class pyart.lazydict.LazyLoadDict(dic)[source]#

A dictionary-like class supporting lazy loading of specified keys.

Keys which are lazy loaded are specified using the set_lazy method. The callable object which produces the specified key is provided as the second argument to this method. This object gets called when the value of the key is loaded. After this initial call the results is cached in the traditional dictionary which is used for supplemental access to this key.

Testing for keys in this dictionary using the “key in d” syntax will result in the loading of a lazy key, use “key in d.keys()” to prevent this evaluation.

The comparison methods, __cmp__, __ge__, __gt__, __le__, __lt__, __ne__, nor the view methods, viewitems, viewkeys, viewvalues, are implemented. Neither is the the fromkeys method.

Parameters:

dic (dict) – Dictionary containing key, value pairs which will be stored and evaluated traditionally. This dictionary referenced not copied into the LazyLoadDictionary and hence changed to this dictionary may change the original. If this behavior is not desired copy dic in the initalization.

Examples

>>> d = LazyLoadDict({'key1': 'value1', 'key2': 'value2'})
>>> d.keys()
['key2', 'key1']
>>> lazy_func = lambda : 999
>>> d.set_lazy('lazykey1', lazy_func)
>>> d.keys()
['key2', 'key1', 'lazykey1']
>>> d['lazykey1']
999

initalize.


Private methods

__contains__(key)

__delattr__(name, /)

Implement delattr(self, name).

__delitem__(key)

Remove a lazy or traditional key from the dictionary.

__dir__()

Default dir() implementation.

__eq__(other)

Return self==value.

__format__(format_spec, /)

Default object formatter.

__ge__(value, /)

Return self>=value.

__getattribute__(name, /)

Return getattr(self, name).

__getitem__(key)

Get the value of a key, evaluating a lazy key if needed.

__getstate__()

Helper for pickle.

__gt__(value, /)

Return self>value.

__init__(dic)

initalize.

__init_subclass__

This method is called when a class is subclassed.

__iter__()

Iterate over all lazy and traditional keys.

__le__(value, /)

Return self<=value.

__len__()

Return the number of traditional and lazy keys.

__lt__(value, /)

Return self<value.

__ne__(value, /)

Return self!=value.

__new__(**kwargs)

__reduce__()

Helper for pickle.

__reduce_ex__(protocol, /)

Helper for pickle.

__repr__()

Return repr(self).

__setattr__(name, value, /)

Implement setattr(self, name, value).

__setitem__(key, value)

Set a key which will not be stored and evaluated traditionally.

__sizeof__()

Size of object in memory, in bytes.

__str__()

Return a string representation of the object.

__subclasshook__(C)

Abstract classes can override this to customize issubclass().