How to convert string to list without eval or exec

Fuzzyman michael at
Tue Mar 16 12:37:09 CET 2004

"Oliver Kurz" <olku at> wrote in message news:<mailman.158.1078818680.19534.python-list at>...
> 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

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 :



More information about the Python-list mailing list