You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bsf-user@jakarta.apache.org by Johannes Zellner <jo...@zellner.org> on 2005/12/22 23:12:33 UTC
jython problem
Hello,
the following program
import org.apache.bsf.*;
public class Test {
public static void main(String args[]) throws BSFException {
Object obj = new BSFManager().eval("jython", "<script>", 0, 0,
new String("import sys\nsys.stderr.write('hello from jython\n')\n"));
}
}
fails with:
Exception in thread "main" org.apache.bsf.BSFException: exception from Jython:
Traceback (innermost last):
(no code object) at line 0
SyntaxError: ('invalid syntax', ('<string>', 1, 1, 'import sys'))
at org.apache.bsf.engines.jython.JythonEngine.eval(Unknown Source)
at org.apache.bsf.BSFManager$5.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.bsf.BSFManager.eval(Unknown Source)
at Test.main(Test.java:7)
what's wrong? -- Or: how can I get jython in bsf working?
--
Johannes
---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org
Re: jython problem
Posted by "Rony G. Flatscher" <Ro...@wu-wien.ac.at>.
Hi Johannes,
not being too familiar with Python/Jython, the following sample program
*does* run with the BSF:
-------------------- cut here ------------------
"""\
A silly little calculator implemented in JPython using
Java components for the UI.
"""
import java
from java import awt
def exit(e): java.lang.System.exit(0)
def getField (f):
t = f.getText ()
if t == '':
return 0
else:
return java.lang.Integer.parseInt (t)
def doMath (e):
n1 = getField (f1)
n2 = getField (f2)
sum.setText (repr (n1 + n2))
diff.setText (repr (n1 - n2))
prod.setText (repr (n1 * n2))
quo.setText (repr (n1 / n2))
f = awt.Frame ('BSH Calculator (jpython)', windowClosing=exit)
f1 = awt.TextField (20, actionPerformed=doMath)
f2 = awt.TextField (20, textValueChanged=doMath)
p = awt.Panel ()
p.setLayout (awt.GridLayout (2, 2))
p.add (awt.Label ('Enter Operand'))
p.add (f1)
p.add (awt.Label ('Enter Operand'))
p.add (f2)
f.add ('North', p)
f.add ("Center", awt.Label ('Results:'))
p = awt.Panel ()
p.setLayout (awt.GridLayout (4, 2))
p.add (awt.Label ('Sum'))
sum = awt.TextField (20)
p.add (sum)
p.add (awt.Label ('Difference'))
diff = awt.TextField (20)
p.add (diff)
p.add (awt.Label ('Product'))
prod = awt.TextField (20)
p.add (prod)
p.add (awt.Label ('Quotient'))
quo = awt.TextField (20)
p.add (quo)
f.add ('South', p)
f.pack ()
f.show ()
f.toFront ()
-------------------- cut here ------------------
It runs without a hitch. (This is running with the latest sources of BSF
from the repository.)
Maybe it serves you as a jump start example?
HTH,
---rony
---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org