Load Python Scripts from Memory

Paul Clinch pclinch at internet-glue.co.uk
Mon Nov 10 15:39:52 EST 2003


dean.ellis at capitaes.co.uK (Dean Ellis) wrote in message news:<4d1a42cd.0311100525.6f846ead at posting.google.com>...
> Hi
> 
> I'm new to python and I have a question. Is it possible to load a
> script/module from memory. I have a requirement in the application I
> am building for scripts to be downloaded from a web site and run
> (these can be pre-compiled scripts). I would rather not have to save
> these scripts to disk then load them if possible.

Possible to get clever with hooking into the import see
http://www.python.org/doc/2.3.2/whatsnew/section-pep302.html
But, mainly look at exec, execfile, eval() and compile(). 
Of course its up to you to determine this is safe, security-wise.
 
> 
> I would also like to add a feature where a compiled module could be
> loaded directly from a resource file.

View the new import from zip file feature in Python2.3!
http://www.python.org/doc/2.3.2/whatsnew/node5.html

> Anyone have any ideas on how this could be done?
> 
> Dean

Regards, Paul Clinch




More information about the Python-list mailing list