reading a list from a file
Rune Strand
rune.strand at gmail.com
Mon Jun 20 18:51:19 EDT 2005
But iif it are many lists in the file and they're organised like this:
['a','b','c','d','e']
['a','b','c','d','e']
['A','B','C','D','E'] ['X','F','R','E','Q']
I think this'll do it
data = open('the_file', 'r').read().split(']')
lists = []
for el in data:
el = el.replace('[', '').strip()
el = el.replace("'", "")
lists.append(el.split(','))
# further processing of lists
but the type problem is still to be resolved ;-)
More information about the Python-list
mailing list