jython

Get data back from Jython scripts using JSR-223

爱⌒轻易说出口 提交于 2019-12-12 18:32:34
问题 I am using Jython 2.5.1 with JSR-223 (i.e. javax.script package) and I expect the last line of the Python script to be returned. For example, after evaluating this script: class Multiplier: def multiply(self, x, y): return x * y Multiplier().multiply(5, 7) I should get back 35, but I get null instead. In other hand it works with this other test: 5 * 7 What am I doing wrong? Here's the Java code: public static void main(String[] args) throws Exception { ScriptEngine engine = new

Jython swing supercall to class “extending” JTextField

久未见 提交于 2019-12-12 18:31:44
问题 I am trying to make a custom TextField similar to the panel here. However if I try calling super for certain methods it goes into infinite recursion leading to the recursion limit (never had a more suiting question for stackoverflow ;) ), the methods are for example paint and add (those two I tried, I guess it is everything inherited). Here is the important code excerpt: class inputWithButtons(JLayeredPane): def __init__(self): self.setLayout(_textFieldWithButtons()) self._fileField =

How do I import a java classname with a dollar sign ($), or refer to a field or method with one, in Jython?

杀马特。学长 韩版系。学妹 提交于 2019-12-12 17:30:52
问题 Naive attempts fail: e.g. from mypackage import SomeClass$ gives javax.script.ScriptException: SyntaxError: no viable alternative at character '$' in at line number 1 This question is unrelated to java nested classes, which are easily importable in Jython. Such a class is for example the scala.Predef$ class, which one can then access with Predef$.foobar . How can I achieve this import? 回答1: I found a solution using Java Reflection like this: from java.lang import Class person = Class.forName(

JDBC driver not found error in monkeyrunner/jython

懵懂的女人 提交于 2019-12-12 17:15:34
问题 I need to Insert something in the DB . im using JDBC as a connector, jython the script , mysql the DB and the script is running in CentOS . my code looks something like this: from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage from com.ziclix.python.sql import zxJDBC db=zxJDBC.connect("jdbc:mysql://XXX.XXX.XXX.XXX:3306/dbname","USER","PASSWORD","org.gjt.mm.mysql.Driver") c=db.cursor() c.execute("INSERT INTO tablename values ('X','X','X')") before that, I downloaded

Getting started with Pylint for Jython (jython2.5.1)

一世执手 提交于 2019-12-12 14:11:15
问题 We have a ton of Jython scripts for our deployment automation; I'd like Pylint to be part of our build pipeline. I downloaded and installed logilab-astng, logilab-common and pylint from here: http://www.logilab.org/857 I installed the logilab libraries successfully using: jython setup.py install However, when I attempt to install pylint i get the following output: C:\temp\pylint-0.22.0.tar.gz\pylint-0.22.0>jython setup.py install running install running build running build_py package init

ImportError: Cannot import site module and its dependencies: No module named site

孤街醉人 提交于 2019-12-12 12:26:39
问题 I am trying to run jython servlets on Windows. I can’t run even the most simple HelloWorld.py. I get the following 500 error: message Servlet.init() for servlet [PyServlet] threw exception ... description Le serveur a rencontré une erreur interne qui l''a empêché de satisfaire la requête. exception javax.servlet.ServletException: Servlet.init() for servlet [PyServlet] threw exception ... cause mère ImportError: Cannot import site module and its dependencies: No module named site Determine if

Jython and the SAX Parser: No more than 64000 entities allowed?

倾然丶 夕夏残阳落幕 提交于 2019-12-12 10:48:42
问题 I've done a simple test of the xml.sax parser in Jython on a large XML file (800 MB) and encountered the following error: Traceback (most recent call last): File "src/project/xmltools.py", line 92, in <module> sys.exit(main()) File "src/project/xmltools.py", line 87, in main parser.parse(open(argv[1], "r")) File "/amd.home/home/user/workspace/jython-2.5.2/Lib/xml/sax/drivers2/drv_javasax.py", line 146, in parse self._parser.parse(JyInputSourceWrapper(source)) File "/amd.home/home/user

Why aren't breakpoints working on the Swing Event Dispatch Thread in PyDev?

折月煮酒 提交于 2019-12-12 09:26:41
问题 I'm using Jython, Swing, and PyDev (Eclipse). Breakpoints are not being hit on any code that runs on the EDT (aka AWT Event Queue?). This includes: Functions that are invoked from a Swing event (eg JButton click) Functions that, via a decorator, are run through SwingUtilities.invokeLater() (See the last example here. Functions that registered as hooks to a Java package (socket class), that I'm using. Swing event code to reproduce: from javax.swing import JFrame, JButton def TestFunc(event):

What is the best way to use python code from Scala (or Java)? [duplicate]

孤街浪徒 提交于 2019-12-12 08:11:55
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Java Python Integration There is some code written in Python and I need to use it from Scala. The code uses some native C. Is it possible to use this from Scala or Java without having to rewrite much? I intend to use the code as a black-box without understanding, so I prefer not to look into it but rather to somehow generate a jar that I can import in my code. 回答1: Why not try Jython?You directly compile python

How do you get a member of an enum in jython?

允我心安 提交于 2019-12-12 06:00:47
问题 enum day{ mon,tue} enum getday(){ return day; } I want to print the day, like "mon" or "tue". Is it possible? 回答1: Just invoke the name method. For example: >>> from java.lang import * >>> s = Thread.currentThread().getState() >>> s RUNNABLE >>> type(s) <type 'java.lang.Thread$State'> >>> s.name() u'RUNNABLE' 回答2: Unless I'm mistaken, it's using the actual Java enum type, in which case you should be able to access the name attribute. Something like day.getName() would be how you would