Returning a value from exec or a better solution

Jack Trades jacktradespublic at
Tue Aug 30 08:31:26 EDT 2011

On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft <rtw at> wrote:

> > That's brilliant and works flawlessly.  Thank you very much!
> If an impementation (as you say up thread) can populate globals
> or locals with whatever they want, then how do you know that last
> item added was the function definition the user supplied ?
> Rob.
> --

I spoke a bit too soon with the "works flawlessly" post.  In addition to
your issue, there is also the problem that supplying an empty environment
does not allow the user to call necessary functions (like scheme_eval).

Why not just get the name from the user

That's probably what I'll end up doing, something similar to:

special_forms = {}

def exec_func_def(symbol, def_string, name=None):
  if name is None:
    special_forms[symbol] = f
    special_forms[symbol] = eval(name)

It just feels kind of hackish to me, when what I really want to do here is
eval an anonymous function.

Nick Zarczynski <>
Pointless Programming Blog <>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list