471,349 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,349 software developers and data experts.

Convert obejct string repr to actual object

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...
Oct 8 '07 #1
2 3995
Tor Erik Sønvisen schrieb:
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...

Try using simplejson.

Diez
Oct 8 '07 #2
On Mon, 08 Oct 2007 21:19:50 +0200, Tor Erik Sønvisen
wrote:
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...

For the benefit of those who think they can make eval "safe", start here:

http://effbot.org/zone/librarybook-core-eval.htm
Here's a good solution:

http://effbot.org/zone/simple-iterator-parser.htm

--
Steven.
Oct 8 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ajay Brar | last post: by
5 posts views Thread by Konrad Mühler | last post: by
3 posts views Thread by Petr Jakes | last post: by
20 posts views Thread by Niyazi | last post: by
reply views Thread by willie | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.