I have a text file with contents such as:
{'InventoryTake':'Key','OtherSceneNode':'Shed','AddOtherScene':'ShedOpen'}
And the code that retrieves the data from the text file:
readin = eventVar.readline()
Results = eval(readin)
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.
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.
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.
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.
I'm using python 2.7.5, and if it helps the order its coming out in is:
{'InventoryTake':'Key','AddOtherScene':'ShedOpen','OtherSceneNode':'Shed'}
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.