Hello,
please, how to execute a python script stored as a string? But let me
impose several limitations, so simple exec wont work:
- if I understood it correctly defining a function in the string and
exec-ing it created the function in current scope. This is something I
really don't want
-
On Mon, 31 Aug 2009 16:29:45 -0700, Ecir Hana wrote:
Hello,
please, how to execute a python script stored as a string? But let me
impose several limitations, so simple exec wont work:
- if I understood it correctly defining a function in the string and
exec-ing it created the function in
On Tue, Sep 1, 2009 at 9:29 AM, Ecir Hana ecir.h...@gmail.com wrote:
- if I understood it correctly defining a function in the string and
exec-ing it created the function in current scope. This is something I
really don't want
Oops, missed that point.
May I ask what is there you don't want,
On Sep 1, 5:31 am, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
You can pass in a global and local namespaces to exec as arguments:
x = 4
ns = {'x': 4}
exec x += 1 in ns
x
4
ns['x']
5
See the docs for details.
Thanks! This is very useful!
You can copy the parts
On Tue, 01 Sep 2009 01:34:33 -0700, Ecir Hana wrote:
You can copy the parts of the current scope into the namespace you pass
to exec, then later copy the revised values out again.
But are you sure you really want to take this approach? exec is up to
ten times slower than just executing the
On Sep 1, 11:32 am, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
But I don't quite understand why is it security
risk. How is it different to run:
exec 'format(your_hdd)'
than:
/bin/python format.py
?
It's not different. But read what I said -- if the string is coming
On Tuesday 01 September 2009 11:32:29 Steven D'Aprano wrote:
Possibly there is a way to have a thread halt itself after a certain
amount of time? I'm not an expert on threads, I've hardly ever used them.
Not automagically, as far as I can see.
You are on your own if you want to somehow kill a