how to read list from file
Ravi Sahni
ganeshsahni07 at gmail.com
Sun Oct 6 12:50:01 EDT 2013
On Sun, Oct 6, 2013 at 10:11 PM, Harvey Greenberg <hjgreenberg at gmail.com> 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 = "[{'a':1, 'b':2}, [1,2,3], 10]"
>> >>> import ast
>> >>> print repr(ast.literal_eval(s))
>> [{'a': 1, 'b': 2}, [1, 2, 3], 10]
>>
>>
>>
>> -tkc
>
> that didn't work. printing it looks like the list because it's the input, but try printing len(repr(ast.literal_eval(s))). It should give 3, but it gives 72 (number of chars).
Please to remove the repr and try again?
Thank you!
--
Ravi
More information about the Python-list
mailing list