jython

how to remove .py from the url in jython

谁说胖子不能爱 提交于 2019-12-11 00:05:50
问题 I am trying to remove .py extension from the url, I am using this tutorial: http://www.jython.org/jythonbook/en/1.0/SimpleWebApps.html my web.xml is as follows: <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" > <servlet> <servlet-name>PyServlet</servlet-name> <servlet-class>org.python

JyNI Eclipse setup

夙愿已清 提交于 2019-12-10 23:19:39
问题 I have the following Java file in Eclipse. package java_python_tutorial; import org.python.core.PyInstance; import org.python.util.PythonInterpreter; public class MainJython { public static void main(String[] args) { PythonInterpreter python = new PythonInterpreter(); python.execfile("pytest/test_np.py"); // PyInstance test = (PyInstance) python.eval("Test()"); // test.invoke("printArr"); python.close(); } } If I include just the Jython JAR, running the file will result in an ImportError: no

Call Python from Java code using Jython cause error: ImportError: no module named nltk

可紊 提交于 2019-12-10 21:31:59
问题 I'm calling a python code from a java code using jython by PythonInterpreter. the python code just tag the sentence: import nltk import pprint tokenizer = None tagger = None def tag(sentences): global tokenizer global tagger tagged = nltk.sent_tokenize(sentences.strip()) tagged = [nltk.word_tokenize(sent) for sent in tagged] tagged = [nltk.pos_tag(sent) for sent in tagged] return tagged def PrintToText(tagged): output_file = open('/Users/ha/NetBeansProjects/JythonNLTK/src/jythonnltk/output

How to unittest unittest TestCases

点点圈 提交于 2019-12-10 21:17:22
问题 I have a unittest.TestCase child, which defines several domain specific assert Checks. I would like to run some unittests to unittest this functionality to control that everything work on future updates. class MyBaseTestCase(unittest.TestCase): def setUp(self): ... def tearDown(self): ... def run(self, result): ... def assertSpec(self, condition, message): ... I want to instantiate MyBaseTestCase in other unit test, like this: class TestBase(unittest.TestCase): def test_assertSpec(self): self

Netbeans not allowing Python 2.6 as default platform (forcing Jython2.5)

北慕城南 提交于 2019-12-10 19:59:30
问题 I am trying to get Netbeans python to run with the default python platform set to Python 2.6.1 (my system python), so in Netbeans I do the following: Tools -> Python Platform Set Python 2.6.1 to 'default' However, it seems impossible to make this stick. Whenever I restart Netbeans it's back to Jython 2.5 again. Moreover, I can obviously autodetect and find Python 2.6.1, but whenever I make it "Default", Netbeans still runs with Jython 2.5 in that very session. (I know this because when I

how can we run python script(which uses nltk and scrapy) from java

冷暖自知 提交于 2019-12-10 19:18:56
问题 I have written python scripts that use scrapy,nltk and simplejson in my project but i need to run them from java as my mentor wants to deploy them on a server and i have very less time to do this.I took a glance at runtime.exec() in java and jython, needless to say that running system commands from java doesn't look simple either. So I would like to know if running the python scripts from java as system command -'python example.py ' using runtime.exec() or alternatively using jython would be

import java ImportError: No module named java

江枫思渺然 提交于 2019-12-10 19:17:11
问题 I seemed to have hit a roadblock and can't figure this out at all, can anyone help me figure out why I am unable to import the java module? Error: Traceback (most recent call last): File "./datasource_config.py", line 3, in ? import java ImportError: No module named java java: 13:30:05 # which java /usr/bin/java beginning of script #!/usr/bin/python import sys import java from java.util import Properties from java.io import FileInputStream from org.python.modules import time lineSep = java

How to know that the interpreter is Jython or CPython in the code? [duplicate]

本秂侑毒 提交于 2019-12-10 14:24:21
问题 This question already has answers here : Can I detect if my code is running on cPython or Jython? (5 answers) Closed 5 years ago . Is there a way to detect that the interpreter that executes the code is Jython or CPython? I have another post: Jython does not catch Exceptions. For this case, if I know the interpreter is Jython, I can have different code that should work. if JYTHON: sys.path.insert(0, os.path.dirname(__file__)) from utils import * else: from .utils import * 回答1: There is an

IJ.close() - Scripting python in ImageJ/FIJI

若如初见. 提交于 2019-12-10 12:04:17
问题 I'm exceptionally new to python/scripting and I'm having a problem. I'm writing the following in Fiji (shortened version of the script is below...) from ij import IJ, ImagePlus from java.lang import Runtime, Runnable import os filepaths = [] for folder, subs, files in os.walk('location/of/files/'): for filename in files: #the next part stops it appending DS files if not filename.startswith('.'): filepaths.append(os.path.abspath(os.path.join(folder, filename,))) for i in filepaths: IJ.open(i);

Running Python modules in Python, from Jython

最后都变了- 提交于 2019-12-10 10:01:53
问题 I have been dropped into a complicated environment, where I am working with a Python library but everything else we have is in Java. We want to be able to access and use the Python library from Java, so we started researching and using Jython. Jython is pretty great, and we are importing the Jython Interpreter into our Java program so that we can access most of the library. However, Jython doesn't quite support everything, and there's not much we can do to get around that. All the paths are