From: D-Man <ds...@ri...> - 2001-05-19 03:21:16
|
On Fri, May 18, 2001 at 06:14:35PM -0700, Harlan Hile wrote: ... | > See jythonc --help for more information and more options. | | i discovered i dont need all the @sig stuff to have jythonc work... | i thought i did because i was using jpythonc 1.1, which didnt work. | with 2.0, I can create a java file, put it into my jar, and import | it. unfortunately, importing it doesnt do much. You only need the @sig stuff if you want to access the _classes_ in the python module from a java class. The limitation to classes only (and not module-level stuff) is a result of java. | >>> import session #this comes from session.class | >>> dir(session) | ['main', 'moduleDictInit'] | | what i would like to see is the same thing that comes from a .py file | >>> import session #this comes from session.py | >>> dir(session) | ['ALTERNATE', 'BIGDECIMAL', 'BINARY', 'BOOLEAN', 'DATE', 'NO_WAIT', | 'OTCCHAR', 'OTCDOUBLE', 'OTCLONG', 'OTCLONGLONG', 'OTCSHORT', | 'PARAMETERLIST', 'PRIMARY', 'PyArray', 'PyLong', 'PyString', 'RC_OK', | 'STRING', 'UNDEFINED', 'WAIT_INFINITE', '__file__', '__name__', 'com', | 'createSession', 'createSessionGroup', 'invokemessage', 'java', | 'parameterlist', 'pythonresponselistener', 'resultCodeToString', | 'session', 'sessiongroup', 'statusToString', 'types'] I think this is a result of Java's limitations. If you use (cp|j)ython and import a python module you will see everything in the module when you use dir(). When you use jythonc to generate java bytecodes everything is put into classes because java requires it. Jythonc generates 2 classes -- a class with the name you gave it (a proxy class) and an innerclass that handles the real work. | it looks like the generated java class is meant to be run by java, | and not used from python. Is there a way to make this work without | rewriting my python code in java? Well, the java classes generated by jythonc are basically just calls into the interpreter to have the same effect as executing python source. If you just want to execute python source, you can do that. The source must be in a file on disk. jar files are a Java concoction that allow bundling java bytecodes (.class files) into a single file. The jvm then loads the _java_ classes from the jar file during program execution. The _jvm_ doesn't know anything about python, and thus doesn't load _python_ modules out of jar files. You do _NOT_ need to rewrite your code in java. All you need to do is work with the systems a little more to get a better understanding of how the python and java environments interact and how to get what you really want from it. If you really want everything to be in a jar file then you must use jythonc to generate java classes from your python source, then compile it to java bytecode. Using the --jar and --depends options to jythonc will instruct it to include all the jython classes (the interpreter itself) that your python source/java bytecodes depend on. It doesn't matter that your java code doesn't access these classes -- they must be java bytecode for the jvm to load it from the jar file. If you really want to leave your python source as python source then it can't go into a jar file because the insides of a jar file are not in "sys.path" -- and can't be because (cp|j)ython look to the disk to find the modules. If you do generate java bytecode then note that there are two .class files for each .py file. If your python module is file.py you will get file.class and file$py.class as the output. AFAIK Jython doesn't save any intermediate pyton bytecode like CPython does with the .pyc files. (Though I have noticed that importing a python module creates the java bytecode for the inner class [file$py.class] in the directory next to the python module) HTH, -D |