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

Date 2011-11-30 17:25 -0600
From Tim Chase <python.list@tim.thechases.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>
Newsgroups comp.lang.python
Message-ID <mailman.3183.1322695556.27778.python-list@python.org> (permalink)

Show all headers | 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