title: Creating a list in python using os.popen
body: <p>Previously, I have been able to create lists using a command similar to the following:</p>
  
  <p><code>os.popen('ls *.fits &gt; samplelist')</code></p>
  
  <p>Now I'm attempting to organize the files into lists by grouping them by number.</p>
  
  <p>The files are named as following:</p>
  
  <p><strong>Name_0000_J.fits, Name_0001_J.fits, Name_0002_J.fits, ect.</strong></p>
  
  <p>I've attempted to run this line of code but it just creates the list <strong>skylist_J_1</strong> and leaves it empty.</p>
  
  <p><code>os.popen('for num in {0000..0089} ; do ls Name_$num\_J.fits &gt;&gt; skylist_J_1 ; done')</code></p>
  
  <p>I ran the above in a command line and it works perfectly. Any insight would be greatly appreciated. </p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I have come up with this solution but it is rather bulky. Hopefully there is a cleaner way to accomplish this.</p>
  
  <pre><code>def MkSkylist(qmin,qmax,name,band,quadrant):
  
      a = qmax-qmin+1
  
      ran = np.arange(qmin,qmax+1)
      num = [0]*a
  
      i = 0
      while i &lt; a:
          num[i] = np.array2string(ran[i]).zfill(4)
          i = i + 1    
  
      os.popen('ls '+name+num[0]+'_'+band+'.fits &gt; skylist_'+band+'_'+quadrant)
  
      i = 1
      while i &lt; a:
          os.popen('ls '+name+num[0]+'_'+band+'.fits &gt;&gt; skylist_'+band+'_'+quadrant)
          i = i + 1
  </code></pre>