Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #56271

Re: how to read list from file

References <fbc6e512-88fa-4de0-80d3-6757fcc52af4@googlegroups.com> <mailman.767.1381022585.18130.python-list@python.org> <61d4be5e-5483-4e1c-9b85-8dac7d6d5ea2@googlegroups.com>
From Ravi Sahni <ganeshsahni07@gmail.com>
Date 2013-10-06 22:20 +0530
Subject Re: how to read list from file
Newsgroups comp.lang.python
Message-ID <mailman.788.1381078230.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Oct 6, 2013 at 10:11 PM, Harvey Greenberg <hjgreenberg@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

how to read list from file Harvey Greenberg <hjgreenberg@gmail.com> - 2013-10-05 18:08 -0700
  Re: how to read list from file Tim Chase <python.list@tim.thechases.com> - 2013-10-05 20:24 -0500
    Re: how to read list from file Roy Smith <roy@panix.com> - 2013-10-05 21:35 -0400
    Re: how to read list from file Harvey Greenberg <hjgreenberg@gmail.com> - 2013-10-06 09:41 -0700
      Re: how to read list from file Harvey Greenberg <hjgreenberg@gmail.com> - 2013-10-06 09:46 -0700
      Re: how to read list from file Ravi Sahni <ganeshsahni07@gmail.com> - 2013-10-06 22:20 +0530
      Re: how to read list from file Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-10-07 09:04 +0300
  Re: how to read list from file Roy Smith <roy@panix.com> - 2013-10-05 21:34 -0400
  Re: how to read list from file Terry Reedy <tjreedy@udel.edu> - 2013-10-06 02:24 -0400
  Re: how to read list from file Harvey Greenberg <hjgreenberg@gmail.com> - 2013-10-06 09:57 -0700
    Re: how to read list from file Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-06 18:24 +0100
    Re: how to read list from file Ravi Sahni <ganeshsahni07@gmail.com> - 2013-10-06 23:08 +0530

csiph-web