String2List: odd function

Fredrik Lundh fredrik at pythonware.com
Wed Jul 21 12:21:28 EDT 1999


Isidor <rodisi01 at my-deja.com> wrote:
> Takes a list-like string, e.g.,:
> 
> "[['itema1', 'itema2'], 'itemb1', ['cheese1', ['cheese1a',
> 'cheese1b'], '2'], ''blah' rest of itemb2', 'zib']"
> 
> and returns *real* lists:
> 
> [['itema1', 'itema2'], 'itemb1', ['cheese1', ['cheese1a',
> 'cheese1b'], '2'], "'blah' rest of itemb2", 'zib']
> 
> Which, in text-world, looks like nothing more than the removal of
> some quotation marks, but in Python-world...well, I don't have to
> tell you what the difference is.

v = eval(s, {"__builtins__": {}})

</F>





More information about the Python-list mailing list