How to convert string to list without eval or exec
Fuzzyman
michael at foord.net
Tue Mar 16 06:37:09 EST 2004
"Oliver Kurz" <olku at web.de> wrote in message news:<mailman.158.1078818680.19534.python-list at python.org>...
> Hello,
>
> could someone give me a solution how to convert a string to a list without using eval or exec?
>
> The string looks like:
>
> '[["abc","abc",["abc","abc"],"abc"],["abc","abc",["abc","abc"],["abc",["abc","abc"]],"abc"],"abc"]'
>
> and should be converted to a list:
>
> [['abc', 'abc', ['abc', 'abc'], 'abc'], ['abc', 'abc', ['abc', 'abc'], ['abc', ['abc', 'abc']], 'abc'], 'abc']
>
> I'm not allowed to use eval or exec.
>
> --
I'm not sure if you now have a working answer to this problem... but
as part of configuration file parser I've written a string to list
parser.....
It will parse a line of text into nested lists.... still
'experimental' but it passes the tests I've done so far....
listparse is included as a module in the ConfigObj 2 zip... see :
http://www.voidspace.org.uk/atlantibots/pythonutils.html#configobj
Regards,
Fuzzy
http://www.voidspace.org.uk/atlantibots/pythonutils.html
More information about the Python-list
mailing list