code: def _fromfile(self, fh):
          
          fh.seek(0)
          data = fh.read(4096)
          if (len(data) < 7) or not (b'0' < data[1:2] < b'8'):
              raise ValueError("Not a Netpbm file:\n%s" % data[:32])
          try:
              self._read_pam_header(data)
          except Exception:
              try:
                  self._read_pnm_header(data)
              except Exception:
                  raise ValueError("Not a Netpbm file:\n%s" % data[:32])
docs: Initialize instance from open file.