use .pyc files via Jython
I am working on building a web interface for a Python 开发者_如何学Gotool. It's being designed using J2EE (Spring).
In the process, I need to make calls to Python functions and hence I am using Jython for the same.
But for some modules I don't have the Python source files, I only have the .pyc
files, and a document listing the methods of that file. I need to know how I can call these functions inside the .pyc
file using jython.
I have tried to de-compile the Python files but since they have been complied with Python 2.7, I am not able find a decompiler to do the job
The 'compiled' python code '.pyc' files are implementation-specific. Even CPython (the standard Python implementation) is not able to import .pyc files generated by a different version of CPython. And is not supposed to. So, I would be surprised if Jython had an ability to run .pyc files created by any of CPython version.
'.pyc' files are not the same as Java bytecode (which is designed to be portable).
Decompilation seems the only way. I think there are some .pyc decompilers available, they should be able to generate Python code that could be run by Jython.
Actually, jython does have experimental support for running cpython-generated pyc files: jython 2.5 has a cpython bytecode interpreter built in.
Read more about how to use it here
http://www.jython.org/jythonbook/en/1.0/ModulesPackages.html?highlight=pycimport#compilation
精彩评论