title: Python: Text file to dictionary whilst preserving order?
body: <p>I have a text file with contents such as:</p>
  
  <pre><code>{'InventoryTake':'Key','OtherSceneNode':'Shed','AddOtherScene':'ShedOpen'}
  </code></pre>
  
  <p>And the code that retrieves the data from the text file:</p>
  
  <pre><code>    readin = eventVar.readline()
      Results = eval(readin)
  </code></pre>
  
  <p>The problem I'm having is that I need to keep my dictionary in order due to the nature of the code it runs. However python stores dictionary keys in random order.</p>
  
  <p>I have tried using an ordered Dictionary to preserve the order, but this doesn't make a difference. I think this is because by the time the ordered dictionary gets a hold of the information, it has already been sorted by whatever is reading it in from the file.</p>
  
  <p>I have tried eval, literal_eval and a json parser to read the data in correctly, but the dictionary always comes out in the wrong order when running the program.</p>
  
  <p>The aim of this part of the program is to allow the text file dictionary to store as many of those pairs as possible (OtherSceneNode and AddOtherScene / TakeOtherScene). So I can't assume there is only one set of those key value pairs.</p>
  
  <p>I'm using python 2.7.5, and if it helps the order its coming out in is:</p>
  
  <pre><code>{'InventoryTake':'Key','AddOtherScene':'ShedOpen','OtherSceneNode':'Shed'}
  </code></pre>
  
  <p>I could redo the text files to take specific lines, but that will make my text files even more complicated and I feel its just avoiding a problem rather than solving one.</p>