code: def render_string(string, sub):
      """
      string: a string, containing formatting instructions
      sub: a dictionary containing keys and values to substitute for
          them.
  
      returns: string % sub
  
      The only difference between this function and the % operator
      is that it raises an exception with a more informative error
      message than the % operator does.
      """
      try:
          finalCode = string % sub
      except Exception as E:
          # If unable to render the string, render longer and longer
          # initial substrings until we find the minimal initial substring
          # that causes an error
          i = 0
          while i <= len(string):
              try:
                  finalCode = string[0:i] % sub
              except Exception as F:
                  if str(F) == str(E):
                      raise Exception(
                          string[0:i]
                          + "<<<< caused exception "
                          + str(F)
                      )
              i += 1
          assert False
      return finalCode
  
imports: from __future__ import absolute_import, print_function, division
  from six.moves import xrange
label_desc: Use image node_id 1 for calling a global function with example usage: render_string(string, sub) and returns: finalCode