title: Python - Import txt in a sequential pattern
body: <p>In the directory I have say, 30 txt files each containing two columns of numbers with roughly 6000 numbers in each column. What i want to do is to import the first 3 txt files, process the data which gives me the desired output, then i want to move onto the next 3 txt files.</p>
  
  <p>The directory looks like:</p>
  
  <p>file0a</p>
  
  <p>file0b</p>
  
  <p>file0c </p>
  
  <p>file1a</p>
  
  <p>file1b</p>
  
  <p>file1c ... and so on. </p>
  
  <p>I don't want to import <em>all</em> of the txt files simultaneously, I want to import the first 3, process the data, then the next 3 and so forth. I was thinking of making a dictionary - though i have a feeling this might involve writing each file name in the dictionary, which would take far too long.</p>
  
  <p>EDIT:</p>
  
  <p>For those that are interested, I think i have come up with a work around. Any feedback would greatly be appreciated, since i'm not sure if this is the quickest way to do things or the most pythonic. </p>
  
  <pre><code>import glob
  
  def chunks(l,n):
    for i in xrange(0,len(l),n):
      yield l[i:i+n]
  
  
     Data = []
  
     txt_files = glob.iglob("./*.txt")
  
     for data in txt_files:
       d = np.loadtxt(data, dtype = np.float64)
       Data.append(d)
  
     Data_raw_all  = list(chunks(Data,3))
  </code></pre>
  
  <p>Here the list 'Data' is all of the text files from the directory, and 'Data_raw_all' uses the function 'chunks' to group the elements in 'Data' into sets of 3. This way you can selecting one element in Data_raw_all selects the corresponding 3 text files in the directory.</p>