Returning a value from exec or a better solution

Arnaud Delobelle arnodel at gmail.com
Tue Aug 30 23:05:07 CEST 2011


On 30 August 2011 13:31, Jack Trades <jacktradespublic at gmail.com> wrote:
>
>
> On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft <rtw at rtw.me.uk> 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 ?

That's not an issue. The last statement that is executed will be the
"def" statement.

>> 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).

You could simply prepend the function definition string with whatever
imports are needed.

-- 
Arnaud



More information about the Python-list mailing list