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


Groups > comp.lang.python > #16462

Re: How convert a list string to a real list

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news-transit.tcx.org.uk!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <tjreedy@udel.edu>
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; 'received:verizon.net': 0.07; 'header:In-reply-to:1': 0.09; 'received:206.46': 0.09; 'received:206.46.173': 0.09; 'subject:string': 0.09; 'carefully.': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'cc:no real name:2**0': 0.20; 'subject:list': 0.21; 'cc:2**0': 0.24; 'skip:" 30': 0.28; 'lists': 0.28; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'received:192.168.1.3': 0.30; 'list': 0.32; 'header:User-Agent:1': 0.33; 'anything': 0.34; 'subject:How': 0.35; 'received:192': 0.37; 'why': 0.39; 'received:192.168': 0.40; 'more': 0.61; "'2',": 0.84
Date Wed, 30 Nov 2011 18:12:14 -0500
From Terry Reedy <tjreedy@udel.edu>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0
MIME-version 1.0
To Hidura <hidura@gmail.com>
Subject Re: How convert a list string to a real list
References <CAHbqn4jog2CzT+ahL3XwPZwvAr8eKN3qHsp2yaJk1VYa1157JQ@mail.gmail.com> <jb4jv2$4nt$1@dough.gmane.org> <jb4r6o$ifb$1@dough.gmane.org> <jb69nu$lv6$1@dough.gmane.org> <CACM+9wF0WHUtRMqB5RXMuu82P8QCZgKN74xvk44vGy6DeLJ2+Q@mail.gmail.com>
In-reply-to <CACM+9wF0WHUtRMqB5RXMuu82P8QCZgKN74xvk44vGy6DeLJ2+Q@mail.gmail.com>
Content-type text/plain; charset=UTF-8; format=flowed
Content-transfer-encoding 7bit
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3182.1322694757.27778.python-list@python.org> (permalink)
Lines 14
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1322694757 news.xs4all.nl 6942 [2001:888:2000:d::a6]:38065
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:16462

Show key headers only | View raw



On 11/30/2011 5:48 PM, Hidura wrote:
> Why you don't make this "['1','2','3']".strip("[]").split(',') work for me

Look more carefully. This is not the same as ast.literal_eval().

 >>> "['1','2','3']".strip("[]").split(',')
["'1'", "'2'", "'3'"]  # list of 3-char strings
 >>> ast.literal_eval("['1','2','3']")
['1', '2', '3']  # list of 1-char strings

Even if it were the same, it would be specific to lists of strings and 
would not work for anything else.

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


Thread

Re: How convert a list string to a real list Terry Reedy <tjreedy@udel.edu> - 2011-11-30 18:12 -0500

csiph-web