Reference values for exec

Garito garito at gmail.com
Wed Oct 28 13:31:11 EDT 2009


Ok, imagine then that I need to execute code from a database query

What I'm trying to do is something similar that Python Scripts in Zope. Do
you know it?

How can I do that?

Thanks you !!

2009/10/28 Dave Angel <davea at ieee.org>

> (You top-posted, so I almost missed your addition.  It's conventional on
> this newsgroup to bottom-post -- inline where appropriate, or at the end)
>
>
> Garito wrote:
>
>> Perhaps but the fact is that I need to execute code from some files in the
>> filesystem and I need to have a common stack for them
>>
>> 2 questions came to my mind:
>>
>> 1.- How can I execute code from files in the filesystem? (I choose exec
>> for
>> that)
>>
>>
> That's what import is for.  Or  __import__() if you need more flexibility.
>
>> 2.- If exec is my only option: how can I use a common stack for them?
>>
>> Thanks
>>
>> 2009/10/28 Dave Angel <davea at ieee.org>
>>
>>
>>
>>> Garito wrote:
>>>
>>>
>>>
>>>> Hi!
>>>> I'm trying to use exec in a recursive way but I have a problem
>>>>
>>>> When I read the manual I understand that the globals and the locals are
>>>> passed by reference but if I try to use it in a recursive way the new
>>>> values
>>>> added in a step are not passed to the next one
>>>>
>>>> Could someone point me how to do that?
>>>>
>>>> Thanks
>>>>
>>>>
>>>>
>>>>
>>>>
>>> see
>>> http://www.catb.org/~esr/faqs/smart-questions.html<http://www.catb.org/%7Eesr/faqs/smart-questions.html>
>>> <http://www.catb.org/%7Eesr/faqs/smart-questions.html>
>>>
>>>
>>> Post some sample code, and show what doesn't work;  maybe you'll get some
>>> help that way.
>>>
>>> I'll point out just one thing:  you cannot add new local variables at
>>> runtime.  locals() should be used to inspect, not to modify.
>>>
>>> See the help text:
>>>  "The contents of this dictionary should not be modified; changes may not
>>> affect the values of local variables used by the interpreter"
>>>
>>> I have no idea if exec() can be safely called recursively.  Most people
>>> successfully avoid calling it at all.
>>>
>>> DaveA
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>>
>


-- 
Mi twitter: http://twitter.com/garito
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091028/181ec51c/attachment-0001.html>


More information about the Python-list mailing list