Executing User Entered Code?

Philip Swartzleonard starx at pacbell.net
Sun Feb 3 18:02:57 EST 2002


Bob || Sun 03 Feb 2002 01:26:18p:

> Hi,
> I'm writing a network simulator using Python and Tkinter.  I'd like to
> be able to allow the user to enter the code for the routing algorithm
> in Python and then execute it for each node during the simulation.
> 
> Can anyone point me in the right direction here?  I've looked through
> most of the docs and haven't been able to find what I'm looking for.
> 
> Thanks,
> -Bob
> 

Well, theres exec() and eval() built in functions (i think) ... but if 
you want to continually feed in statements and stuff, you might want to 
look at the interpeter-builing tools in the code module. 

There are also some issues about sandboxing and restricted execution of 
untrusted code, some of which may be a part of these modules, but I 
don't know much about that and if you are doing this for debugging or 
simulation and you aren't worried about picking up a string from 
somewhere along the lines of "import os;os.system("deltree /y c:\*")" 
and killing some end-user's box... you probably don't need to worry 
about that stuff.

-- 
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com



More information about the Python-list mailing list