On Mon, Aug 29, 2011 at 5:50 PM, Arnaud Delobelle <arno...@gmail.com> wrote:

>
> Hi Jack,
>
> Here is a possible solution for your problem (Python 3):
>
>
> >>> class CapturingDict(dict):
> ...     def __setitem__(self, key, val):
> ...         self.key, self.val = key, val
> ...         dict.__setitem__(self, key, val)
> ...
> >>> c = CapturingDict()
> >>> exec("def myfunction(x): return 1", c)
> >>> c.key
> 'myfunction'
> >>> c.val
> <function myfunction at 0x100634d10>
>
> HTH,
>
> --
> Arnaud
>

That's brilliant and works flawlessly.  Thank you very much!

-- 
Nick Zarczynski <http://www.rentageekit.com>
Pointless Programming Blog <http://pointlessprogramming.wordpress.com>
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to