code: def prepend_name_scope(name, import_scope):
    
    # Based on tensorflow/python/framework/ops.py implementation.
    if import_scope:
      try:
        str_to_replace = r"([\^]|loc:@|^)(.*)"
        return re.sub(str_to_replace, r"\1" + import_scope + r"/\2",
                      tf.compat.as_str_any(name))
      except TypeError as e:
        # If the name is not of a type we can process, simply return it.
        logging.warning(e)
        return name
    else:
      return name
docs: Prepends name scope to a name.