Convert a string to a list

rh0dium steven.klass at gmail.com
Tue Apr 24 16:59:20 CEST 2007


Hi all,

I am using pexpect to drive another tool.  Some of the data I get back
would be better suited as a list and I want to know a simple way to
parse the data to push it into a list.

For example

I get the following string back.  I want to convert this to a list:

'("." ".." "cdslib_cleanup.py" "cadence.py"
"cdsinit_cdsenv_cleanup.py")'

should be:
["." ".." "cdslib_cleanup.py" "cadence.py"
"cdsinit_cdsenv_cleanup.py"]

It should be able to handle embeded lists like this:
'("." ("cadence.py" "foo_cleanup.py") "cdslib_cleanup.py" "cadence.py"
"cdsinit_cdsenv_cleanup.py")'

should become
["." ["cadence.py" "foo_cleanup.py"] "cdslib_cleanup.py" "cadence.py"
"cdsinit_cdsenv_cleanup.py"]

Is there some exisitng code which will handle this task?




More information about the Python-list mailing list