[Tutor] Isolation of code
noufal at nibrahim.net.in
Sun Oct 8 09:06:09 CEST 2006
I'm working on a little project that's similar to tcltutor for python.
I have a string which has some python code. I "compile" and "eval" this
to get the output. So far so good. However, when this happens, the
evaluation is happening in the current namespace so I'm afraid of
symbols being redefined and messed up.
What I want to do is to create a separate namespace for all the code so
that I can execute it without worrying about symbol mangling.
Something like if the code I have is
code = """
I'd like to be able to create a separate module called (say) "tester"
<contents of the code variable>
then say something like
to actually run the code. This way, the namespace would be separate.
Any idea how I can go about this? I'm guessing I should use the parser
module to actually create the construct and then compile it but that looks
little hairy. Is there something I'm missing? Any suggestions?
More information about the Tutor