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


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

Re: How convert a list string to a real list

Started byTerry Reedy <tjreedy@udel.edu>
First post2011-11-30 18:12 -0500
Last post2011-11-30 18:12 -0500
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 Terry Reedy <tjreedy@udel.edu> - 2011-11-30 18:12 -0500

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

FromTerry Reedy <tjreedy@udel.edu>
Date2011-11-30 18:12 -0500
SubjectRe: How convert a list string to a real list
Message-ID<mailman.3182.1322694757.27778.python-list@python.org>

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.

[toc] | [standalone]


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


csiph-web