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


Groups > comp.lang.python > #16464

Re: How convert a list string to a real list

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!feeder3.eweka.nl!81.171.88.15.MISMATCH!eweka.nl!lightspeed.eweka.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '"""': 0.07; 'subject:string': 0.09; 'throw': 0.09; 'trailing': 0.09; 'skip:[ 20': 0.12; '"can\'t': 0.16; '-tkc': 0.16; 'delimited': 0.16; 'double,': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'message-id:@tim.thechases.com': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'cc:no real name:2**0': 0.20; 'subject:list': 0.21; 'header:In-Reply-To:1': 0.22; 'appear': 0.23; 'breaks': 0.23; 'cc:2**0': 0.24; 'skip:" 30': 0.28; 'cc:addr:python.org': 0.29; 'closing': 0.30; 'strings,': 0.30; 'whitespace': 0.30; 'header:User-Agent:1': 0.33; 'things': 0.34; 'subject:How': 0.35; 'used,': 0.38; 'should': 0.39; 'why': 0.39; 'raw': 0.40; 'might': 0.40; 'more': 0.61; 'leading': 0.62; 'touch': 0.70; 'row,': 0.84
Date Wed, 30 Nov 2011 17:25:46 -0600
From Tim Chase <python.list@tim.thechases.com>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111120 Icedove/3.1.16
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 8bit
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-Source
X-Source-Args
X-Source-Dir
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.3183.1322695556.27778.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1322695556 news.xs4all.nl 6873 [2001:888:2000:d::a6]:38503
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:16464

Show key headers only | View raw


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

because it breaks on things like

   s = """
     [[1,2,3],42,'''triple the fun!''', "can't touch this, 
eh?",r'"Back\\\slashes?!", she said.', [4,5,6]]
     """

Commas can be embedded in strings, strings can be delimited with 
single, double, or triple quotes, raw strings can be used, more 
than one opening or closing "["/"]" can appear in a row, leading 
or trailing whitespace might throw you off...using 
ast.literal_eval() should just Do the Right Thing™.

-tkc

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


Thread

Re: How convert a list string to a real list Tim Chase <python.list@tim.thechases.com> - 2011-11-30 17:25 -0600

csiph-web