code: def expandvars(str, vars):
      i = 0
      while i < len(str):
          i = k = str.find("$", i)
          if i < 0:
              break
          i = i + 1
          var = str[i : i + 1]
          i = i + 1
          if var == "(":
              j = str.find(")", i)
              if j < 0:
                  break
              var = str[i:j]
              i = j + 1
          if var in vars:
              str = str[:k] + vars[var] + str[i:]
              i = k
      return str
  
imports: import os
  import parsesetup
label_desc: Use image node_id 4 for calling a global function with example usage: expandvars(str, vars) and returns: str