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:
object
Callable class that will substitute symbol names using
substitutions
substitution dictionary.
- class bw2parameters.mangling.OnlySelected(substitutes=None)[source]#
Bases:
asteval.astutils.NameFinder
Change name of all symbols already redefined in
substitutes
.
- class bw2parameters.mangling.PrefixNameAdder(prefix, context=None)[source]#
Bases:
asteval.astutils.NameFinder
Change name of all symbols by adding a prefix, unless name already in
context
.
- bw2parameters.mangling.mangle_formula(string, prefix, context=None)[source]#
Add
prefix
to all variable names in formulastring
, except those incontext
or 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
prefix
to each key indct
. Also updates the formulas, if present.Adds
original
to each value indct
with the original key name.Returns the new dictionary, and a dictionary of name substitutions like
{old: new}