Embedding Python in Python

Phil Frost indigo at bitglue.com
Wed Aug 18 20:35:21 CEST 2004

You probably want something like this:

globalDict = {}
exec(stringOfPythonCodeFromUser, globalDict)

globalDict is now the global namespace of whatever was in
stringOfPythonCodeFromUser, so you can grab values from that and
selectivly import them into your namespace.

On Wed, Aug 18, 2004 at 02:26:00PM -0500, Robey Holderith wrote:
> Anyone know a good way to embed python within python?
> Now before you tell me that's silly, let me explain
> what I'd like to do.
> I'd like to allow user-defined scriptable objects.  I'd
> like to give them access to modify pieces of my classes.
> I'd like to disallow access to pretty much the rest of
> the modules.
> Any ideas/examples?
> -Robey

More information about the Python-list mailing list