saving pre-compiled scripts

Derek van Vliet dvanvliet at 3dna.net
Thu Jun 30 15:58:29 EDT 2005


Hi,

I'm working on an application that reads python scripts from XML
elements and compiles them during my app's startup process using. The
application then runs the resulting compiled PyCodeObjects using
PyEval_EvalCode as they are needed.

Now I'm wondering if its possible to pre-compile the scripts and save
the PyCodeObjects in a binary file (or in CDATA in an XML element) and
have them ready to run when the application starts up.

My only constraint is that I need to be able to load the scripts from
memory (which is why using Py_CompileString has worked well for me).

Is there any way I can get the size of a PyCodeObject so that I could
save it to a binary file? If I did that would it run correctly if I
reloaded it and tried to Eval it? Can I load a pyc file from memory
somehow?

Any guidance would be greatly appreciated.

Thanks,
Derek




More information about the Python-list mailing list