Executing User Entered Code?

Fernando Pérez fperez528 at yahoo.com
Sun Feb 3 15:12:38 EST 2002


Bob wrote:

> 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.
> 

You may be interested in looking at my pet project, IPython at 
http://www-hep.colorado.edu/~fperez/ipython/

Even though it started as a python interpreter shell, I later made it a 
trivially embeddable module. With a single call (there's example code for 
that purpose provided in the distribution) you can open an interpreter shell 
at any point in your program execution which knows about its environment.

Note however that there are *many* security issues with this, which may or 
may not be important in your context. IPython does *not* restrict access to 
any library or statement. If you need sandboxing, you'll have to add that 
around it yourself.

Cheers,

f



More information about the Python-list mailing list