Convert obejct string repr to actual object
arkanes at gmail.com
Mon Oct 8 21:42:23 CEST 2007
On 10/8/07, Tor Erik Sønvisen <torerik81 at gmail.com> wrote:
> I've tried locating some code that can recreate an object from it's
> string representation...
> The object in question is really a dictionary containing other
> dictionaries, lists, unicode strings, floats, ints, None, and
> I don't want to use eval, since I can't trust the source sending the
> object.... I'm sure someone must have had the same need and created
> code for it... Maybe Pypy has what I need??? Haven't looked though...
> Tor Erik
> PS: The string repr is created by a server outside of my control...
You'll need to write your own parser. PyParsing has an example that
can parse much of the Python syntax, you can probably extract the
object-literal parts of that and use it as a base for your
More information about the Python-list