I have a question with Python 2.5 . First, I save a file in list format as below:
list_f = open("list.txt", "w")
list = [{"a" : "b", "c" : 100}, {"a" : "c", "c" : 101}]
print >> list_f, list
So, we get a list.txt like this:
[{'a' : 'b', 'c': 100}, {'a' : 'c', 'c' : 101}]
This is its only line in this file. Notice that there are two dict objects in the list and each dict has a value in String and a value in integer .
My question is how to load the file and re-create a list object as the former one.
returns
outputas a real list of dictionaries and not as its string representationf.read()would return.Anyway, if you are both writing and reading the file, use some serialization interface, such as
cPickleorjson.