Pickle will work, but the disadvantage is that it is a binary format specific to Python. Save as JSON for readability and reuse in other applications:
import json
LoL = [ range(5), list("ABCDE"), range(5) ]
with open('Jfile.txt','w') as myfile:
json.dump(LoL,myfile)
Now the file contains:
[[0, 1, 2, 3, 4], ["A", "B", "C", "D", "E"], [0, 1, 2, 3, 4]]
To return it later:
with open('Jfile.txt','r') as infile:
newList = json.load(infile)
print newList
source
share