Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16420
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: How convert a list string to a real list |
| Date | 2011-11-30 01:54 -0500 |
| References | <CAHbqn4jog2CzT+ahL3XwPZwvAr8eKN3qHsp2yaJk1VYa1157JQ@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3145.1322636080.27778.python-list@python.org> (permalink) |
On 11/30/2011 1:20 AM, 郭军权 wrote:
> Good after
> I have a string liststr = '["aaaa","bbbb","ccc"]' ,and I need convert it
> to a list like list = ["aaaa","bbbb","ccc"],what can id do?
The easiest -- and most dangerous -- way is
>>> eval('["aaaa","bbbb","ccc"]')
['aaaa', 'bbbb', 'ccc']
But DO NOT eval unexamined strings from untrusted sources. The reason is
that it is much the same as letting an untrusted person sit unsupervised
as the keyboard of your computer with a command window open. You would
not want to eval
"from os import system; system('<command to delete files>')"
where '<command...>' is replaced by something obnoxious for your
operating system.
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: How convert a list string to a real list Terry Reedy <tjreedy@udel.edu> - 2011-11-30 01:54 -0500
csiph-web