Re: how to read list from file

2013-10-06 Thread Jussi Piitulainen
Harvey Greenberg writes: > On Saturday, October 5, 2013 7:24:39 PM UTC-6, Tim Chase wrote: > > >>> s = "[{'a':1, 'b':2}, [1,2,3], 10]" > > >>> import ast > > >>> print repr(ast.literal_eval(s)) > > [{'a': 1, 'b': 2}, [1, 2, 3], 10] > > that didn't work. printing it looks like the list bec

Re: how to read list from file

2013-10-06 Thread Ravi Sahni
On Sun, Oct 6, 2013 at 10:27 PM, Harvey Greenberg wrote: > On Saturday, October 5, 2013 7:08:08 PM UTC-6, Harvey Greenberg wrote: >> I am looping as for L in file.readlines(), where file is csv. >> >> >> >> L is a list of 3 items, eg, [{'a':1, 'b':2}, [1,2,3], 10] Note that the >> first item is a

Re: how to read list from file

2013-10-06 Thread Mark Lawrence
On 06/10/2013 17:57, Harvey Greenberg wrote: On Saturday, October 5, 2013 7:08:08 PM UTC-6, Harvey Greenberg wrote: I am looping as for L in file.readlines(), where file is csv. L is a list of 3 items, eg, [{'a':1, 'b':2}, [1,2,3], 10] Note that the first item is a dir and 2nd is a list, so

Re: how to read list from file

2013-10-06 Thread Harvey Greenberg
On Saturday, October 5, 2013 7:08:08 PM UTC-6, Harvey Greenberg wrote: > I am looping as for L in file.readlines(), where file is csv. > > > > L is a list of 3 items, eg, [{'a':1, 'b':2}, [1,2,3], 10] Note that the first > item is a dir and 2nd is a list, so parsing with split doesn't work. Is

Re: how to read list from file

2013-10-06 Thread Ravi Sahni
On Sun, Oct 6, 2013 at 10:11 PM, Harvey Greenberg wrote: > On Saturday, October 5, 2013 7:24:39 PM UTC-6, Tim Chase wrote: >> Python 2.7.3 (default, Jan 2 2013, 13:56:14) >> [GCC 4.7.2] on linux2 >> Type "help", "copyright", "credits" or "license" for more >> information. >> >>> s = "[{

Re: how to read list from file

2013-10-06 Thread Harvey Greenberg
On Sunday, October 6, 2013 10:41:33 AM UTC-6, Harvey Greenberg wrote: > On Saturday, October 5, 2013 7:24:39 PM UTC-6, Tim Chase wrote: > > > On 2013-10-05 18:08, Harvey Greenberg wrote: > > > > > > > I am looping as for L in file.readlines(), where file is csv. > > > > > > > > > > > > >

Re: how to read list from file

2013-10-06 Thread Harvey Greenberg
On Saturday, October 5, 2013 7:24:39 PM UTC-6, Tim Chase wrote: > On 2013-10-05 18:08, Harvey Greenberg wrote: > > > I am looping as for L in file.readlines(), where file is csv. > > > > > > L is a list of 3 items, eg, [{'a':1, 'b':2}, [1,2,3], 10] Note that > > > the first item is a dir and 2

Re: how to read list from file

2013-10-05 Thread Terry Reedy
On 10/5/2013 9:08 PM, Harvey Greenberg wrote: I am looping as for L in file.readlines(), where file is csv. I believe 'for L in file:' does the same, more efficiently, even in 2.7. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list

Re: how to read list from file

2013-10-05 Thread Roy Smith
In article , Tim Chase wrote: > sounds like you want ast.literal_eval(): This sounds like a better idea than either of my earlier suggestions! -- https://mail.python.org/mailman/listinfo/python-list

Re: how to read list from file

2013-10-05 Thread Roy Smith
In article , Harvey Greenberg wrote: > I am looping as for L in file.readlines(), where file is csv. > > L is a list of 3 items, eg, [{'a':1, 'b':2}, [1,2,3], 10] Note that the first > item is a dir and 2nd is a list, so parsing with split doesn't work. Is > there a way to convert L, which i

Re: how to read list from file

2013-10-05 Thread Tim Chase
On 2013-10-05 18:08, Harvey Greenberg wrote: > I am looping as for L in file.readlines(), where file is csv. > > L is a list of 3 items, eg, [{'a':1, 'b':2}, [1,2,3], 10] Note that > the first item is a dir and 2nd is a list, so parsing with split > doesn't work. Is there a way to convert L, whic

how to read list from file

2013-10-05 Thread Harvey Greenberg
I am looping as for L in file.readlines(), where file is csv. L is a list of 3 items, eg, [{'a':1, 'b':2}, [1,2,3], 10] Note that the first item is a dir and 2nd is a list, so parsing with split doesn't work. Is there a way to convert L, which is a string, to the list of 3 items I want? -- ht