title: How to sort file names in a particular order using python
body: <p>Is there a simple way to sort files in a directory in python? The files I have in mind come in an ordering as </p>
  
  <pre><code>file_01_001
  file_01_005
  ...
  file_02_002
  file_02_006
  ...
  file_03_003
  file_03_007
  ...
  file_04_004
  file_04_008
  </code></pre>
  
  <p>What I want is something like</p>
  
  <pre><code>file_01_001
  file_02_002
  file_03_003
  file_04_004
  file_01_005
  file_02_006
  ...
  </code></pre>
  
  <p>I am currently opening them using <code>glob</code> for the directory as follows:</p>
  
  <pre><code>for filename in glob(path):    
      with open(filename,'rb') as thefile:
          #Do stuff to each file
  </code></pre>
  
  <p>So, while the program performs the desired tasks, it's giving incorrect data if I do more than one file at a time, due to the ordering of the files. Any ideas?</p>