Convert obejct string repr to actual object

Carsten Haese carsten at uniqsys.com
Fri Oct 12 13:14:11 EDT 2007


On Fri, 2007-10-12 at 17:41 +0100, English, Mark wrote:
> > From: Tor Erik Sønvisen
> > Date: October 8th 2007
> > I've tried locating some code that can recreate an object from
> > it's string representation... 
> On a related note I've wondered about this:
> >>> class Foo(object): pass
> >>> f = Foo()
> >>> s = repr(f)
> >>> s
> '<__main__.Foo object at 0x007CBAB0>'
> 
> So how do I get f back from s ?
> Obviously this is open to abuse. I just wondered if a mechanism existed short of writing
> a C-extension which parses that string, casts the hex number to a PyObject *, INCREFs it,
> and gives it back...

I can't help but wonder, do you often find yourself having to locate an
object from its hexadecimal address?

-- 
Carsten Haese
http://informixdb.sourceforge.net





More information about the Python-list mailing list