REGISTER NOW: DdS Autumn School! 🇨🇭 Grosshöchstetten (Switzerland) 🗓️ 6.-11. October 2024

bw2io.strategies.parameterization#

Module Contents#

Classes#

ReservedVariableNameSubstitutor

A class to substitute reserved variable names in formulas with their uppercase versions.

Attributes#

RESERVED

variable_subtitutor

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'
fix_formula(string)[source]#

Substitute reserved variable names in a formula with their uppercase versions.

Parameters#
stringstr

The formula containing reserved variable names to be replaced.

Returns#
str

The updated formula with reserved variable names replaced with their uppercase versions.

fix_variable_name(string)[source]#

Substitute a reserved variable name with its uppercase version if necessary.

Parameters#
stringstr

The variable name to be checked and possibly replaced.

Returns#
str

The updated variable name, replaced with its uppercase version if it was a reserved variable name.

bw2io.strategies.parameterization.RESERVED[source]#
bw2io.strategies.parameterization.variable_subtitutor[source]#