Re: How convert a list string to a real list

2011-11-30 Thread Alec Taylor
Dammit, been awake too long researching on the Internet, but I finally reached the Last Page On Thu, Dec 1, 2011 at 3:25 PM, Ben Finney wrote: > Steven D'Aprano writes: > >> On Wed, 30 Nov 2011 17:12:10 -0500, Terry Reedy wrote: >> >> > I think it would be better if safe_eval were available as a

Re: How convert a list string to a real list

2011-11-30 Thread Ben Finney
Steven D'Aprano writes: > On Wed, 30 Nov 2011 17:12:10 -0500, Terry Reedy wrote: > > > I think it would be better if safe_eval were available as an easily > > accessible builtin and dangerous_eval were tucked away in a module ;-). > > +10 You do realise that any vote outside the range −1 thr

Re: How convert a list string to a real list

2011-11-30 Thread Steven D'Aprano
On Wed, 30 Nov 2011 17:12:10 -0500, Terry Reedy wrote: > I think it would be better if safe_eval were available as an easily > accessible builtin and dangerous_eval were tucked away in a module ;-). +10 -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How convert a list string to a real list

2011-11-30 Thread Tim Chase
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

Re: How convert a list string to a real list

2011-11-30 Thread Terry Reedy
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("['

Re: How convert a list string to a real list

2011-11-30 Thread Hidura
Why you don't make this "['1','2','3']".strip("[]").split(',') work for me El nov 30, 2011 10:16 p.m., "Terry Reedy" escribió: > On 11/30/2011 3:58 AM, Peter Otten wrote: > >> Terry Reedy wrote: >> >> On 11/30/2011 1:20 AM, 郭军权 wrote: >>> Good after I have a string liststr = '["","

Re: How convert a list string to a real list

2011-11-30 Thread Terry Reedy
On 11/30/2011 3:58 AM, Peter Otten wrote: Terry Reedy wrote: On 11/30/2011 1:20 AM, 郭军权 wrote: Good after I have a string liststr = '["","","ccc"]' ,and I need convert it to a list like list = ["","","ccc"],what can id do? The easiest -- and most dangerous -- way is >>> ev

Re: How convert a list string to a real list

2011-11-30 Thread Peter Otten
Terry Reedy wrote: > On 11/30/2011 1:20 AM, 郭军权 wrote: >> Good after >> I have a string liststr = '["","","ccc"]' ,and I need convert it >> to a list like list = ["","","ccc"],what can id do? > > The easiest -- and most dangerous -- way is > >>> eval('["","","ccc"]') > ['

Re: How convert a list string to a real list

2011-11-29 Thread Alec Taylor
Arnaud: Already showed that solution On Wed, Nov 30, 2011 at 6:09 PM, Arnaud Delobelle wrote: > > On Nov 30, 2011 6:21 AM, "郭军权" wrote: >> >> Good after >>     I have a string  liststr = '["","","ccc"]' ,and I need convert >> it to a list like list = ["","","ccc"],what can id do?

Re: How convert a list string to a real list

2011-11-29 Thread Arnaud Delobelle
On Nov 30, 2011 6:21 AM, "郭军权" wrote: > > Good after > I have a string liststr = '["","","ccc"]' ,and I need convert it to a list like list = ["","","ccc"],what can id do? > Thanks. > Look up the json module. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: How convert a list string to a real list

2011-11-29 Thread Terry Reedy
On 11/30/2011 1:20 AM, 郭军权 wrote: Good after I have a string liststr = '["","","ccc"]' ,and I need convert it to a list like list = ["","","ccc"],what can id do? The easiest -- and most dangerous -- way is >>> eval('["","","ccc"]') ['', '', 'ccc'] But DO NOT eva

Re: How convert a list string to a real list

2011-11-29 Thread Alec Taylor
import json s = json.dumps([1, 2, 3, 4]) # '[1, 2, 3, 4]' l = json.loads(s) # [1, 2, 3, 4] 2011/11/30 郭军权 : > Good after > I have a string liststr = '["","","ccc"]' ,and I need convert > it to a list like list = ["","","ccc"],what can id do? > Thanks. > > > -- > 郭军权 > 清华大学网络中

How convert a list string to a real list

2011-11-29 Thread 郭军权
Good after I have a string liststr = '["","","ccc"]' ,and I need convert it to a list like list = ["","","ccc"],what can id do? Thanks. -- 郭军权 清华大学网络中心网络安全实验室 guojunquan{at}gmail.com -- http://mail.python.org/mailman/listinfo/python-list