code: def get_file_handle(file_name, mode="r"):
      use_gzip_open = False
      # if want to read from file, check that is gzipped and set
      # use_gzip_open to True if it is
      if mode == "r" or mode == "rb":
          if is_gzipped(file_name):
              mode = "rb"
              use_gzip_open = True
      # Also check if gz or gzip is in the name, and use gzip open
      # if writing to the file.
      if re.search(".gz$", filename) or re.search(".gzip", filename):
          # check for the case where the file name implies the file
          # is gzipped, but the file is not actually detected as gzipped,
          # and warn the user accordingly
          if mode == "r" or mode == "rb":
              if use_gzip_open == False:
                  print(
                      "Warning: file has gz or gzip in name, but was not"
                      " detected as gzipped"
                  )
          if mode == "w":
              use_gzip_open = True
              # I think write will actually append if the file already
              # exists...so you want to remove it if it exists
              if os.path.isfile(file_name):
                  os.remove(file_name)
      if use_gzip_open:
          return gzip.open(file_name, mode)
      else:
          return open(file_name, mode)
  
imports: from __future__ import division
  from __future__ import print_function
  from __future__ import absolute_import
  import sys
  import os
  import os.path
  import numpy
  from collections import namedtuple
  from collections import OrderedDict
  import json
  import deeplift
  import tensorflow
label_desc: Use image node_id 12 for calling a global function with example usage: get_file_handle(file_name, mode) and returns: gzip, open