def replace_variables ( self , source : str , variables : dict ) -> str : try : replaced = re . sub ( "{{(.*?)}}" , lambda m : variables . get ( m . group ( 1 ) , "" ) , source ) except TypeError : replaced = source return replaced
python variable replacement in string
Replace {{ variable - name }} with stored value .
def replace_variables(self, source: str, variables: dict) -> str:
        """Replace {{variable-name}} with stored value."""
        try:
            replaced = re.sub(
                "{{(.*?)}}", lambda m: variables.get(m.group(1), ""), source
            )
        except TypeError:
            replaced = source
        return replaced