Convert obejct string repr to actual object

Michael Spencer mahs at telcopartners.com
Mon Oct 8 20:20:50 EDT 2007


Tor Erik Sønvisen wrote:
> Hi,
> 
> 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
> booleans.
> 
> 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...
> 
> Regards,
> Tor Erik
> 
> PS: The string repr is created by a server outside of my control...

This recipe should get you most of what you need:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469

HTH

Michael




More information about the Python-list mailing list