[Tutor] Storing Dictionaries Externally

Daniel Watkins daniel at thewatkins.org.uk
Sun Oct 23 01:41:51 CEST 2005


Currently, I'm writing a little project which needs to store a
dictionary in an external file (so it can be accessed by another
program). However, no matter how much I try, I cannot get Python to
import the dictionary from the file properly. However, I know the
problem. Whatever format I put the data in within the file (either as a
dictionary or a list of tuples to 'dict()') Python reads it as a string,
rather than a dictionary or list of tuples.

My question is essentially this:
How do I convert a string into a dictionary or list of tuples, assuming
it's syntax is correct (ie. it is actually how a dictionary or list of
tuples would look if I were defining it).

Thanks in advance,
Dan



More information about the Tutor mailing list