jython

Jython: Determine the number of arguments a Java method takes at runtime

假如想象 提交于 2019-12-13 05:45:06
问题 I'm trying to write an object inspector for Java objects in Jython, and I want to determine how many arguments a given Java method expects. Is there any way to do that in python, or do I have to use Java reflection for that. To explain, I'd like to call all "get..." methods of a Java object that don't take any arguments: from java.util import Date, ArrayList def numberOfArguments(fct): # Some magic happens here return 0 def check(o): print("") print(type(o).name) for fctName in dir(o): if not

Jython does not catch Exceptions

ε祈祈猫儿з 提交于 2019-12-13 05:38:25
问题 Jython doesn't have the -m option, and it raises an error with from .utils import * . The solution is not to use relative path sys.path.insert(0, os.path.dirname(__file__)) from utils import * As I need to use the code both Jython and CPython, I came up with this command: try: from .utils import * except Exception: # Jython or Python with python context/context.py invocation sys.path.insert(0, os.path.dirname(__file__)) from utils import * However, Jython doesn't seem to catch the exception,

Getting journal articles by category: Liferay Portlet written in Python

喜你入骨 提交于 2019-12-13 04:50:41
问题 I am trying to write a simple Liferay portlet in Python. The portlet will show a list of categories and when clicked will show a list of Web Content articles (journal articles) of a certain structure. I am able to get the list of categories but cannot find a way using the liferay api to get a list of articles by category? I have searched allover but it seems to me the method should be on this page: http://docs.liferay.com/portal/6.1/javadocs/com/liferay/portlet/journal/service

using docmd to receive queue-id of a mail from smtp server

核能气质少年 提交于 2019-12-13 04:13:16
问题 I have written a code in jython 2.5, which uses the smtplib sendmail to send mail over a smtp server. Below is a simple snippet of the code mail = MIMEMultipart('mixed') mail['Subject'] = mail_subject mail['FROM']=UstrSender mail['To']=UstrReceivers mail['Cc']=UstrCC mail_p2=MIMEText(mail_html, 'html', 'utf-8') mail.attach(mail_p2) #Connection to SMTP #Enter SMTP Server Details, In case your server do require authentication modify authentication parameter below and uncomment s = smtplib.SMTP

TypeError: nextDouble(): self arg can't be coerced to java.util.Random

落花浮王杯 提交于 2019-12-13 03:39:46
问题 I'm having problem with this Random java thing in jython. I'm coding bukkit plugins in python. Here's the code: class hween(PythonPlugin): def CandyChance(self): chance = self.cfg.getDouble("main.candydropchance", 50) / 100 #in config, it's 10, so I must do this to get it like 0.1... return chance @hook.event("block.BlockBreakEvent", "HIGHEST") def onBlockBreakEvent(event): chance = pyplugin.CandyChance() print chance #When I print chance out, it's 0.1 (10 is in config) which is good I

Can't change log detail levels permanently with a Jython script (WAS 7)

跟風遠走 提交于 2019-12-13 03:00:31
问题 I'm trying to change WebSphere's Log Detail Levels with a Jython script: .. AdminTask.setTraceSpecification('[-serverName server1 -nodeName qnode -traceSpecification com.ibm.*=all=enabled]') AdminConfig.save() .. After successfully running the script I'm checking "Logging and Tracing > {server_name} > Diagnostic trace service > Change log detail levels. The Runtime tab reflects the setting (the traceSpecification) I've entered in my script, but the Configuration tab remains unchanged, so, my

Python alternative to _winreg

陌路散爱 提交于 2019-12-13 02:17:41
问题 I am accessing a python script using jython and apparently the _winreg module is not supported. Are there any alternatives to this module? I am using jython 2.5. 回答1: You'll need to access the Windows registry via Java instead. 来源: https://stackoverflow.com/questions/6522650/python-alternative-to-winreg

When copying a picture in Jython/Python, how to copy X pixels less with every row

不想你离开。 提交于 2019-12-13 01:29:49
问题 I'm writing a code in Jython, that will copy part of one picture into an empty picture, but I want it to copy (let's say) 10 pixels less with each next row. I don't think I make sense, let me explain with an example. A picture 100 pixels by 100 pixels, the program will copy the first row (100pixels) of pixels into the new picture, but for second row of pixels I want it to copy only 90 pixels, then for the third row 80 pixels, and so on. Here I have a code that will copy part of a picture, but

How do you intercept a keyboard interrupt (CTRL-C) in Jython?

孤街浪徒 提交于 2019-12-12 23:02:09
问题 This is what I've tried... from sun.misc import Signal from sun.misc import SignalHandler class InterruptHandler(SignalHandler): def handle(self): print "Shutting down server..." Signal.handle(Signal("INT"),InterruptHandler()) It's based on this http://www.javaspecialists.co.za/archive/Issue043.html, but evidently I'm missing something. 回答1: Looks like a bug in Jython. There are some workarounds given there. 回答2: I was facing similar problem before. This is how I get it resolved. First,

Does Eclipse PyDev (Jython) pull classpath from M2Eclipse?

人走茶凉 提交于 2019-12-12 18:34:19
问题 While trying to run Jython Scripts in Eclipse using PyDev, I noticed that the Jython run configuration was not pulling the java classpath value from maven/m2eclipse. Has anybody configured eclipse so that PyDev pulls the correct classpath from maven? Notes: I can in fact run jython scripts, and import classes from the jre, but my maven dependencies do not appear on the classpath when interpreting the Jython scripts I have seen the question/answer Using Jython with M2Eclipse and have used