bw2io.strategies.parameterization#
Attributes#
Classes#
A class to substitute reserved variable names in formulas with their uppercase versions. |
Module Contents#
- 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.
- matches[source]#
A list of tuples, where each tuple contains a compiled regular expression pattern and a substitution string for each reserved symbol.
- Type:
list
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'
- fix_formula(string)[source]#
Substitute reserved variable names in a formula with their uppercase versions.
- Parameters:
string (str) β The formula containing reserved variable names to be replaced.
- Returns:
The updated formula with reserved variable names replaced with their uppercase versions.
- Return type:
str
- fix_variable_name(string)[source]#
Substitute a reserved variable name with its uppercase version if necessary.
- Parameters:
string (str) β The variable name to be checked and possibly replaced.
- Returns:
The updated variable name, replaced with its uppercase version if it was a reserved variable name.
- Return type:
str