bw2parameters.mangling#
Attributes#
Classes#
Callable class that will substitute symbol names using |
|
Change name of all symbols already redefined in |
|
Change name of all symbols by adding a prefix, unless name already in |
Functions#
|
Add |
|
Add |
|
Substitute symbol names in |
Module Contents#
- class bw2parameters.mangling.FormulaSubstitutor(substitutions)[source]#
Bases:
objectCallable class that will substitute symbol names using
substitutionssubstitution dictionary.
- class bw2parameters.mangling.OnlySelected(substitutes=None)[source]#
Bases:
asteval.astutils.NameFinderChange name of all symbols already redefined in
substitutes.
- class bw2parameters.mangling.PrefixNameAdder(prefix, context=None)[source]#
Bases:
asteval.astutils.NameFinderChange name of all symbols by adding a prefix, unless name already in
context.
- bw2parameters.mangling.mangle_formula(string, prefix, context=None)[source]#
Add
prefixto all variable names in formulastring, except those incontextor builtin to Python,math, ornumpy.Uses asteval and astunparse.
Returns the formula as a string.
Example usage:
… code-block:: python
>>> mangle_formula("log(foo * bar) + 7 / baz", "pre", ['bar']) '(log((pre__foo * bar)) + (7 / pre__baz))'
- bw2parameters.mangling.prefix_parameter_dict(dct, prefix)[source]#
Add
prefixto each key indct. Also updates the formulas, if present.Adds
originalto each value indctwith the original key name.Returns the new dictionary, and a dictionary of name substitutions like
{old: new}