jython

Appending values to a key if key already exists (python/jython)

浪尽此生 提交于 2019-12-04 14:23:24
I have a list that I need to make into a dictionary. The list has duplicate (soon to be) keys which have different values. How do I find these keys and append the new values to it? list=[q:1,w:2,q:7] dictionary= q:1,7 w:2 Thanks in advance Make the values in your dictionary lists, so that you have: dictionary = {'q': [1, 7], 'w': [2] } etc. ie, your one-item values are one-item lists. This means when you have another 'q' , you can do this: dictionary['q'].append(5) Except that dictionary['q'] will be a KeyError the first time you do it, so use setdefault instead: dictionary.setdefault('q', [])

Why does my Swing window keep closing itself after a few seconds?

给你一囗甜甜゛ 提交于 2019-12-04 14:04:31
Edit: In case the multiple tags are confusing, I'm working in Jython. Here's my SSCCE : from javax.swing import JFrame window = JFrame('Test', defaultCloseOperation = JFrame.EXIT_ON_CLOSE, size = (800, 600)) window.visible = True The window opens, sits there for a few seconds, and then closes. So far the only solution I've found is to add while True: pass to the end, which would seem to indicate that the problem is that window is going out of scope, so it gets cleaned up and has to close. This may in fact be another symptom of the same problem I have encountered previously . However, I don't

Using Jython From Eclipse Plugin

天涯浪子 提交于 2019-12-04 12:24:01
I am having a tough time getting jython to work properly when run from an Eclipse plugin. I have a simple object factory that loads a python module conforming to a Java Interface. All of this works fine in standalone mode. However, when I package this as an eclipse plugin, I get a different error based on a few variables: Given that my java package is com.foo. 1) If I run without modifying any paths, I get: "No module named foo" 2) If I then add my java jars to the sys.path using: PythonInterpreter interp = new PythonInterpreter(null, new PySystemState()); PySystemState sys = Py.getSystemState

Running HtmlUnit with Jython - issue with startup on command line

﹥>﹥吖頭↗ 提交于 2019-12-04 12:16:50
I tried to run HtmlUnit with Jython following this tutorial: http://blog.databigbang.com/web-scraping-ajax-and-javascript-sites/ but it does not work for me. I am unable to import the com.gargoylesoftvare packages, there are only some HTML files in HtmlUnit folder, which I need to import somehow? The tutorial says to run python script like this: /opt/jython/jython -J-classpath "htmlunit-2.8/lib/*" gartner.py and I try to run: java -jar /Users/adam/jython/jython.jar -J-classpath "htmlunit-2.8/lib/*" gartner.py My problem is I am getting an "Unknown option: J-classpath". But there is not even

How to get urllib3 and requests working with jython 2.7 beta 1?

心已入冬 提交于 2019-12-04 12:15:36
问题 Smart folks, I would like to use the awesome requests module in my jython program. It installs and runs just fine in python but I cannot get it to install in jython. I have tried both Jython 2.7a2 and 2.7b1 on mac and ubuntu and get the same errors related to urllib3. First installed ez_setup.py as mentioned in How can I use jython setup.py install? Then run easy_install from within the jython bin directory results in exception: NameError: name 'CERT_NONE' is not defined gautam-mbp:bin gautam

Java: Scripting language (macro) to embed into a Java desktop application

强颜欢笑 提交于 2019-12-04 11:32:58
问题 I am writing a graphics application in Java. Eventually I would like to build in a scripting language so things are programmable. Which language library do you recommend? Likely suspects are: Rhino (JavaScript) JRuby (Ruby) Jython (Python) Less likely candidates are: Whip up my own language using JavaCC LuaJava (Lua) Groovy JavaFX Script-Fu The target audience are probably not hardcore programmers, so less arcane language is preferred. My guess is that JavaScript is more acceptable by them

Jython 2.5.1: Calling From Java into __main__ - how to pass in command line args?

岁酱吖の 提交于 2019-12-04 11:15:53
I'm using Jython from within Java; so I have a Java setup similar to below: String scriptname="com/blah/myscript.py" PythonInterpreter interpreter = new PythonInterpreter(null, new PySystemState()); InputStream is = this.getClass().getClassLoader().getResourceAsStream(scriptname); interpreter.execfile(is); And this will (for instance) run the script below: # myscript.py: import sys if __name__=="__main__": print "hello" print sys.argv How I pass in 'commandline' arguments using this method ? (I want to be able to write my Jython scripts so that I can also run them on the commandline with

Jython does not load PYTHONPATH into sys.path

北战南征 提交于 2019-12-04 08:43:23
According to what I've read, sys.path should be set by PYTHONPATH. In Python, it works that way, but not in Jython. I can circumvent with -Dpython.path=... but I'd like to know why Jython isn't playing nicely. qa@Scantron:/tmp/pip-build-qa/robotframework> echo $PYTHONPATH /usr/lib64/python2.7 qa@Scantron:/tmp/pip-build-qa/robotframework> jython Jython 2.2.1 on java1.7.0_17 Type "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path ['', '/usr/share/jython/Lib', '__classpath__'] >>> ^D qa@Scantron:/tmp/pip-build-qa/robotframework> jython -Dpython.path=/usr/lib64

In Jython, can I make an inline anonymous class that implements a Java interface?

早过忘川 提交于 2019-12-04 08:24:26
In Java, I can say Thread t = new Thread(){ public void run(){ // do stuff } } (or something much like that) to declare an anonymous class inline. This is most useful for making event handlers or other callback sorts of things, that in any sensible language wouldn't require an object to own them in the first place. I face the same problem in Jython -- I want to define an event handler, but I don't want to build a whole standalone class to do so. Ideally, I'd just be able to pass a lambda and be done with it, but if this is possible, I can't find it anywhere in the docs. davidrmcharles Here are

How do I catch SocketExceptions in MonkeyRunner?

混江龙づ霸主 提交于 2019-12-04 06:12:49
When using MonkeyRunner, every so often I get an error like: 120830 18:39:32.755:S [MainThread] [com.android.chimpchat.adb.AdbChimpDevice] Unable to get variable: display.density 120830 18:39:32.755:S [MainThread] [com.android.chimpchat.adb.AdbChimpDevice]java.net.SocketException: Connection reset From what I've read, sometimes the adb connection goes bad, and you need to reconnect. The only problem is, I'm not able to catch the SocketException . I'll wrap my code like so: try: density = self.device.getProperty('display.density') except: print 'This will never print.' But the exception is