Jython .py to .class confusion
scott
smarsh at hotmail.com
Wed May 22 23:38:32 EDT 2002
I'm trying to use "jythonc" in Jython 2.1 to create a .class file from a
.py file. I've read Chapter 9 of Bruce Eckels draft of "Thinking in
Patterns" (http://64.78.49.204/) which has a section on this very task,
but I am unable to grok it.
It looks like I need:
1. an "@sig" string as the first line of my method to deal with strong /
weak typing issues (?something like "@sig public javax.swing.???
getPicks()" ?)
2. Information about Java package creation from the python code.
Apparently this involves the --package flag of jythonc.
I'm stuck here. Perhaps if I give a concrete example, someone will show
the modifications / steps required to create a .class file from this .py
file.
Assume this file (loto3.py) is the only file on a floppy disk in a
Windows 2000 system running Jython 2.1 on Java 1.4.0:
---------------------------------------------------
import random
import javax.swing as swing
def getPicks():
li = []
i = 0
numPicks = int(swing.JOptionPane.showInputDialog("How many picks?:
"))
theRange = int((swing.JOptionPane.showInputDialog("What range?: ")))
+ 1
while i < numPicks:
elem = random.randrange(1, theRange)
if elem not in li:
li.append(elem)
i = i+1
conv = str(li)
return swing.JOptionPane.showMessageDialog(None, "Your #'s are: " +
conv)
getPicks()
--------------------------------------------------
The program pops up 2 Swing input boxes for a lottery number picker
(e.g. you could request 6 "random" numbers out of 49 possibilities) and
produces a string in a Swing message box containing the randomly
generated numbers.
When I tried to use jythonc, I got the following:
---------------------------------------------------
C:\jython-2.1>jythonc.bat a:loto3.py
processing loto3
Required packages:
javax.swing
Creating adapters:
Creating .java files:
loto3 module
Compiling .java to .class...
Compiling with args: ['C:\\j2sdk1.4.0\\bin\\javac', '-classpath',
'C:\\jython-2.
1\\jython.jar;;.\\jpywork;a:;C:\\jython-2.1\\Tools\\jythonc;C:\\jython-2.1\\.;C:
\\jython-2.1\\Lib;C:\\jython-2.1', '.\\jpywork\\loto3.java']
-------------------------------------------------------
This resulted in a loto3.class file in the jpywork subdirectory of the
jython directory. When I tried to run it (java loto3) I got the
following:
--------------------------------------------------------------
C:\jython-2.1\jpywork>java loto3
Exception in thread "main" java.lang.NoClassDefFoundError:
org/python/core/PyObject
---------------------------------------------------------------
I peeked in the java source file generated by jythonc in the jpywork
subdirectory (loto3.java) and the first line is an import statement
"import org.python.core.*;"
Thanks in advance for any help
More information about the Python-list
mailing list