On Fri, 07 Jul 2006 19:57:02 +0200, Fredrik Lundh wrote: > Steven D'Aprano wrote: > >> Personally, I would never use eval on any string I didn't write myself. If >> I was thinking about evaluating a user-string, I would always write a >> function to parse the string and accept only the specific sort of data I >> expected. In your case, a quick-and-dirty untested function might be: > > for a more robust approach, you can use Python's tokenizer module, > together with the iterator-based approach described here: > > http://online.effbot.org/2005_11_01_archive.htm#simple-parser-1 > > here's a (tested!) variant that handles lists and dictionaries as well: [snip code]
Thanks Fredrik, that's grand. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list