code: def get_extver_list(img, extname='SCI'):
      
      if isinstance(img, str):
          img = fits.open(img, memmap=False)
          img.close()
      elif not isinstance(img, fits.HDUList):
          raise TypeError("Argument 'img' must be either a file name (string) "  \
                          "or a fits.HDUList object.")
  
      # when extver is None - return the range of all FITS extensions
      if extname is None:
          extver = list(range(len(img)))
          return extver
  
      if not isinstance(extname, str):
          raise TypeError("Argument 'extname' must be either a string "          \
              "indicating the value of the 'EXTNAME' keyword of the extensions " \
              "whose versions are to be returned or None to return "             \
              "extension numbers of all HDUs in the 'img' FITS file.")
  
      extname = extname.upper()
  
      extver = []
      for e in img:
          #if not isinstance(e, fits.ImageHDU): continue
          hkeys = list(map(str.upper, list(e.header.keys())))
          if 'EXTNAME' in hkeys and e.header['EXTNAME'].upper() == extname:
              extver.append(e.header['EXTVER'] if 'EXTVER' in hkeys else 1)
  
      return extver
docs: Return a list of all extension versions of 'extname' extensions.
      'img' can be either a file name or a HDU List object (from fits).