title: python reading in files for a specific column range
body: <p>I'm writing a script that reads in one file containing a list of files and performing gaussian fits on each of those files. Each of these files is made up of two columns (wv and flux in the script below). My small issue here is how do I limit the range based "wv" values? I tried using a "for" loop for this but I get errors related to the fit (which I don't get if I don't limit the "wv" range).</p>
  
  <pre><code>import numpy as np
  from scipy.optimize import curve_fit
  import matplotlib.pyplot as plt
  
  
  fits = []
  wvi_b = []
  wvi_r = []
  
  p = open("file_input.txt","r")
  for line in p:
      fits.append(str(line.split()[0]))
      wvi_b.append(float(line.split()[1]))
      wvi_r.append(float(line.split()[2]))
  p.close()
  
  for j in range(len(fits)):
      wv = []
      flux = []
      f = open("%s"%(fits[j]),"r")
      for line in f:
          wv.append(float(line.split()[0]))
          flux.append(float(line.split()[1]))
      f.close()
  
      def gauss(x,a,b,c,a1,b1,c1,d):
          func = a*np.exp(-((x-b)**2)/(2.0*(c)**2)) + a1*np.exp(-((x-b1)**2)/(2.0*(c1)**2))+d
          return func
  
      for wv in range(6450, 6575):
          guess=(0.8,wvi_b[j],3.0,1.0,wvi_r[j],3.0,1.0)
          popt,pconv=curve_fit(gauss,wv,flux,guess)
          print popt[1], popt[4]
          ymod=gauss(wv,*popt)
          plt.plot(wv,ymod)
          plt.plot(wv,flux,marker='.')
          plt.show()
  </code></pre>