By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,985 Members | 1,574 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,985 IT Pros & Developers. It's quick & easy.

saving pre-compiled scripts

P: n/a

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

Any guidance would be greatly appreciated.


Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
Another thing which may be important to note re: my constraints is that
each script is essentially being run as a function.

In fact, every script element I parse in XML gets wrapped in a function
def before I send it to Py_CompileString.

I then PyEval the result of that function, and then run
Py_CompileString again, passing only the automatically generated
function call.

The result of the second Py_CompileString is what I pass to
PyEval_EvalCode whenever my app needs to run that script (function).

Jul 19 '05 #2

P: n/a
I probably should have also mentioned that my application is written in
C++ and using the Python/C API.

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.