title: Python: Too many open files error
body: <p>I'm working on an assignment were I need to to read data from 150 files and manipulate them. this needs to be done about 73 times.</p>
  
  <pre><code>count = 0    
  for date in daterange(start, end):
          #Adjusting for correct format
          day = date.strftime("%d")
          month = date.strftime("%m")
  
  #appending files
  filenames.append(glob.glob('*'+month+day+'filenamehere.nc'))
  
  #Opening files
  for i in filenames[count]:
          megadatalist.append(netCDF4.Dataset(i,'r'))
  
  count += 1
  
  if count % interval == 0:
      ~calculation stuff here
  </code></pre>
  
  <p>after doing the operations needed I attempt to empty the list and close the datasets:</p>
  
  <pre><code>for i in megadatalist:
      i.close
  megadatalist = []
  </code></pre>
  
  <p>However after running through about 34 of the datasets consisting of 150 files I get a Runtime Error: Too many open files</p>
  
  <p>Do I not close the files correctly? Or what is going on, any help is appreciated!</p>