code: def read(fil):
      
      if os.path.splitext(fil)[-1] == '.gz':
          return gzip.open(fil, 'rb')
      elif os.path.splitext(fil)[-1] == '.zip':
          zf = zipfile.ZipFile(fil, 'r')
          return zf.open(zf.infolist()[0].filename)
      else:
          return open(fil, 'r')
docs: Returns a file handler and detects gzipped files.