From: Jim A. <ji...@tr...> - 2001-03-19 18:38:30
|
Question: How do I comvert a compiled code object to some kind of bytestream? 'Pickle' can't handle PyCode ("can't pickle ...PyTableCode object"), and PyCode is not serializable. Am I missing something or is there no way to do this easily? Backround: I am prototyping a program that uses Jython to allow users to design forms by entering Jython expressions which are evaluated based on a large set of XML data that is 'scoped' into the PythonInterpreter beforehand. (Example: 'Customer.Name' or 'for p in Customer.Phones: print p') We have built a GUI that displays the forms and allows entry of the expressions, the 'definition' of the form is stored in XML along with Fonts, justification, and other formatting info. After each expression is evaluated the result is 'massaged' using various Java routines to build a complete page. The previous version used JavaScript (Rhino) but I'm trying to switch it to Python to make it easier for the form designers. I'm having a problem, though, with the speed: when interpreting expressions Jython is half the speed of Rhino: this is critical for this app. I timed the compile compared the the 'eval' and found the compile takes 90% of the time: PyCode code = __builtin__.compile(evalLine, "<string>", "eval"); // 90% PyObject result = python.eval( (PyCode)code ); // 10% !! If I could store the compiled 'code objects' within the forms somehow I think I could increase the speed of the forms 10x, but I can't figure out a way to get some kind of 'bytestream' of the code object. -- __o Jim Adrig _ \<,_ ji...@tr... ' `/ ' ` ___________ `-' `-' Flon's Law: There is not now, and never will be, a language in which it is the least bit difficult to write bad programs. |