Providing Python scripting to a Python application

Bjorn Pettersen BPettersen at NAREX.com
Fri Dec 27 12:18:03 EST 2002


> From: Erik Max Francis [mailto:max at alcyone.com] 
> 
> "Gonçalo Rodrigues" wrote:
> 
> > Check out the exec statement. Basically it goes as:
> > 
> > exec <code> in <globals>
> 
> There's also a
> 
> 	exec S in D1, D2
> 
> form where S is the string representing the code, D1 is the 
> dictionary representing the globals, and D2 is that 
> representing the locals.

... and S can also be an open file or a code object, which could potentially make a speed difference if you're executing this frequently. To create code objects, check the Library Reference (http://www.python.org/doc/current/lib/built-in-funcs.html) for the built in function compile, and perhaps also class codeop.Compile (http://www.python.org/doc/current/lib/module-codeop.html).

-- bjorn




More information about the Python-list mailing list