bw2calc.dictionary_manager#

Classes#

DictionaryManager

Class that handles dictionaries which can be remapped or reverse.

ReversibleRemappableDictionary

A dictionary that can be easily remapped or reversed.

Functions#

resolved(f)

Decorator that resolves a partial function before it can be used

Module Contents#

class bw2calc.dictionary_manager.DictionaryManager[source]#

Class that handles dictionaries which can be remapped or reverse.

Usage:

dm = DictionaryManager()
dm.foo = {1: 2}
dm.foo[1]
>> 2
_dicts[source]#
class bw2calc.dictionary_manager.ReversibleRemappableDictionary(obj)[source]#

Bases: collections.abc.Mapping

A dictionary that can be easily remapped or reversed.

Perhaps overkill, but at the time it was easier than creating many dictionaries on the LCA object itself.

Example usage:

In [1]: from bw2calc.dictionary_manager import ReversibleRemappableDictionary

In [2]: d = ReversibleRemappableDictionary({1: 2})

In [3]: d.reverse
Out[3]: {2: 1}

In [4]: d.remap({1: "foo"})

In [5]: d['foo']
Out[5]: 2

In [6]: d.original
Out[6]: {1: 2}

In [7]: d.reverse
Out[7]: {2: 'foo'}

In [8]: d.unmap()

In [9]: d[1]
Out[9]: 2
remap(mapping)[source]#

Transform the keys based on the mapping dict mapping.

mapping doesn’t need to cover every key in the original.

Example usage:

{1: 2}.remap({1: “foo”} >> {“foo”: 2}

unmap()[source]#

Restore dict to original state.

property original[source]#
property reversed[source]#
bw2calc.dictionary_manager.resolved(f)[source]#

Decorator that resolves a partial function before it can be used