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


Groups > comp.lang.python > #16464 > unrolled thread

Re: How convert a list string to a real list

Started byTim Chase <python.list@tim.thechases.com>
First post2011-11-30 17:25 -0600
Last post2011-11-30 17:25 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#16464 — Re: How convert a list string to a real list

FromTim Chase <python.list@tim.thechases.com>
Date2011-11-30 17:25 -0600
SubjectRe: How convert a list string to a real list
Message-ID<mailman.3183.1322695556.27778.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web