Read python list from a file -


i printed list l file using

f = open('a.txt', 'a') f.write(str(l)) 

now, how can retrieve list file.

and list l list of list of dictionaries.

its not best way serialize data file, conversion string list use ast.literal_eval.

e.g.

import ast  l = [['dir/path', 'other/path'],['path/path', 'blah/xyz']] open('a.txt', 'a') f:     f.write(str(l))  open('a.txt') fread:     s = fread.read()     l2 = ast.literal_eval(s)  print type(l2) in l2:     print  

there plenty of better ways, pickle or json standout choices.

note append complete list file each time, repeated runs of code write file result in file containing invalid python syntax cannot evalled list.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -