Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #56230
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python.list@tim.thechases.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.008 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'subject:file': 0.07; '[1,': 0.09; 'parsing': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'jan': 0.12; '-tkc': 0.16; '2.7.3': 0.16; '3],': 0.16; 'ast': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'looping': 0.16; 'wrote:': 0.18; 'split': 0.19; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'string,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'subject:list': 0.30; 'work.': 0.31; 'file': 0.32; 'subject:from': 0.34; 'convert': 0.35; 'there': 0.35; 'charset:us-ascii': 0.36; 'list': 0.37; 'list,': 0.38; '2nd': 0.60; 'first': 0.61; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'received:50.22': 0.84; 'subject:read': 0.84; '2013,': 0.91; 'items,': 0.91 |
| Date | Sat, 5 Oct 2013 20:24:39 -0500 |
| From | Tim Chase <python.list@tim.thechases.com> |
| To | Harvey Greenberg <hjgreenberg@gmail.com> |
| Subject | Re: how to read list from file |
| In-Reply-To | <fbc6e512-88fa-4de0-80d3-6757fcc52af4@googlegroups.com> |
| References | <fbc6e512-88fa-4de0-80d3-6757fcc52af4@googlegroups.com> |
| X-Mailer | Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=US-ASCII |
| Content-Transfer-Encoding | 7bit |
| X-AntiAbuse | This header was added to track abuse, please include it with any abuse report |
| X-AntiAbuse | Primary Hostname - boston.accountservergroup.com |
| X-AntiAbuse | Original Domain - python.org |
| X-AntiAbuse | Originator/Caller UID/GID - [47 12] / [47 12] |
| X-AntiAbuse | Sender Address Domain - tim.thechases.com |
| X-Get-Message-Sender-Via | boston.accountservergroup.com: none |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.767.1381022585.18130.python-list@python.org> (permalink) |
| Lines | 28 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1381022585 news.xs4all.nl 15931 [2001:888:2000:d::a6]:60923 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:56230 |
Show key headers only | View raw
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, which is a string, to
> the list of 3 items I want?
sounds like you want ast.literal_eval():
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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