Re: reading a list from a file

2005-06-20 Thread Rune Strand
:-/ You're right! -- http://mail.python.org/mailman/listinfo/python-list

Re: reading a list from a file

2005-06-20 Thread Konstantin Veretennicov
On 6/20/05, David Bear <[EMAIL PROTECTED]> wrote: > I have a file that contains lists -- python lists. sadly, these > are not pickled. These are lists that were made using > a simple print list statement. Sad, indeed. But what kind of objects they held? Only ints? Ints and strings? Arbitrary objec

Re: reading a list from a file

2005-06-20 Thread John Machin
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 dat

Re: reading a list from a file

2005-06-20 Thread Rune Strand
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()

Re: reading a list from a file

2005-06-20 Thread Jordan Rastrick
If you decide to steer clear of eval, the following comes close to what you want, and is somewhat Pythonic (I feel): def back_to_list(str): return str.strip("[]").split(", ") >>> s = "[1, 2, 3, 4, 5, 6]" >>> back_to_list(s) ['1', '2', '3', '4', '5', '6'] So parsing the list structure is prett

Re: reading a list from a file

2005-06-20 Thread Jordan Rastrick
Be careful, though - make sure you can absolutely trust your source of data before calling eval on it. If an unauthorised person could forseeably modify your file, then they could insert a string containing arbitrary Python code into it in place of your list, and then running your program would ca

Re: reading a list from a file

2005-06-20 Thread Tim Williams
- Original Message - From: "David Bear" <[EMAIL PROTECTED]> > I have a file that contains lists -- python lists. sadly, these are not > pickled. These are lists that were made using a simple print list > statement. > > Is there an easy way to read this file into a list again? I'm thin