Jython Embedding - how do I compile and exec with params
Chris Liechti
cliechti at gmx.net
Tue Feb 5 15:32:49 EST 2002
tonygreen at techie.com (Tony Green) wrote in
news:cefe12a8.0202050531.33412d38 at posting.google.com:
> I am writing a scripting extension mechanism to a big server project
> we've built over the last year and a half.
>
> What I want to acheive is
> - system authors upload scripts (via a web front end)
> - the system checks and compiles the script
> - stashes the compiled script away against a named event.
>
> When the even occurs the compiled script is called by the system
> with a list of parameters (current user id, various numbers
> describing the system state).
[...]
> (3) put the variables into the local namespace and then execute the
> script (without a named method or class) - but this means that I
> would have to clean down the local namespace each time (- and anyway
> what is it local to?).
you can pass a dictionary to exec: "exec code in dict" so you don't
need to clean up. just build one root dict, clone it and update it
with additional params. no clreanup needed.
root = {...}
copy = {}
copy.update(root)
copy[additional] = param
exec code in copy
you can also make the user code import some module whitch provides the
data throug variables or function calls.
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list