reading a list from a file
John Machin
sjmachin at lexicon.net
Mon Jun 20 19:58:16 EDT 2005
Rune Strand wrote:
> 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 ;-)
>
Try this:
["O'Reilly, Fawlty, and Manuel", '""', ',', '"Hello", said O\'Reilly']
:-)
More information about the Python-list
mailing list