bw2io.strategies.parameterization
#
Module Contents#
Classes#
A class to substitute reserved variable names in formulas with their uppercase versions. |
Attributes#
- class bw2io.strategies.parameterization.ReservedVariableNameSubstitutor[source]#
A class to substitute reserved variable names in formulas with their uppercase versions.
This class replaces reserved Python keywords, as well as built-in function names, with their uppercase versions in a given formula string.
Attributes#
- symbolsset
A set of reserved Python keywords and built-in function names.
- matcheslist
A list of tuples, where each tuple contains a compiled regular expression pattern and a substitution string for each reserved symbol.
Examples#
>>> variable_substitutor = ReservedVariableNameSubstitutor() >>> formula = "sum = a + b + max(1, 2)" >>> variable_substitutor.fix_formula(formula) 'SUM = a + b + MAX(1, 2)'
>>> variable_name = "sum" >>> variable_substitutor.fix_variable_name(variable_name) 'SUM'