title: How to Use Data From a FITS File Directly (Not converting it to a text file)
body: <p>I have a bunch of values written in a FITS file. There's like 320,000 points in each column... The columns that I need are 3 columns called, detx, dety, and energy. 
  I need to use this data for my program. 
  I know how to convert this FITS file into a txt file (example shown below) and then use the data, but how can I use the data directly? For example,how could I get the data from this FITS file, and then print it out in python? </p>
  
  <p>Here's an example of how to convert the fits file into a text file:</p>
  
  <pre><code>from astropy.io import fits
  #This is what the file is called
  hdulist = fits.open('acisf02149N003_evt2.fits.gz')
  hdulist.info()
  tbdata = hdulist[1].data
  
  #This prints it out into a text file
  f=open('ChandraXraysources.txt','w+')
  
  #This chooses only the detx, dety, and energy columns I was talking about
  detxvect=tbdata.field('detx')
  detyvect=tbdata.field('dety')
  detzvect=tbdata.field('energy')
  
  #This lists at the top of the text file the names of each column 
  f.write('Chandra X-ray source, RA(x),dec(y),energy  \r\n')
  
  for i in range(len(detxvect)):
      f.write('%e  %e  %e\r\n' %(detxvect[i],detyvect[i],detzvect[i]))
  
  print(detxvect[0]) 
  </code></pre>