FAQ Database Discussion Community


Syntax error when trying to find the length of a list using 'len' function

python,syntax,jython
Hi there I'm trying to find the length of a list for use in a method to find the average of all the numbers in said list but when I try to run the code len(numList) It gives me a syntax error and i don't know why. Everything I've read...

Jython/Python Name not found globally

python,jython
Please help me, I got this error: diagonal Name not found globally. A local or global name could not be found. You need to define the function or variable before you try to use it in any way. Could you also help with how I can use print.now() and display...

How to obtain UTF-8 reader in PythonInterpreter (jython)?

java,python,utf-8,jboss,jython
I am using embedded Jython (version 2.5.3) in my web application and I try to do this in my Java code: PythonInterpreter pythonInterpreter = new PythonInterpreter(); pythonInterpreter.exec("import codecs"); pythonInterpreter.exec("codecs.getreader('utf8')"); But I get this error: File "<string>", line 1, in <module> File "__pyclasspath__/codecs$py.class", line 920, in getreader LookupError: no codec search...

How to make a part of the picture grayscale in JES?

python,image,jython,partial,manipulation
Hi there I'm trying to play around with my code and can't really seem to figure out how to make part of my code into a grayscale. This is my code: def grayScale(picture): xstop=getWidth(picture)/2 ystop=getHeight(picture)/2 for x in range(0,xstop): for y in range(0,ystop): oldpixel= getPixel(picture,x,y) colour=getColor(oldpixel) newColor=(getRed(oldpixel),getGreen(oldpixel),getBlue(oldpixel))/3 setColor(picture,(newColor,newColor,newColor)) repaint(picture) nP=makePicture(pickAFile())...

jython.exe “2.7.0 final release” failed execution on my Windows OS

pip,jython
OS: Windows 7, 64-bit Here I learn that the latest version of Jython (downloads/installs as "2.7.0") includes the "ensurepip" module, which hopefully installs pip. This is what I get... NB there is no drive "Z:" on my machine D:\apps\jython2.7.0\bin>jython -m ensurepip Traceback (most recent call last): File "<string>", line 444,...

How to Edit files using web application

design,web,jython
All, I have a requirement where user would like to edit the files using web application. I know there would be a concurrency issues. But i want to know if there is a way to do it efficiently in the web application, may be using Jython or any other framework....

attempting to load .csv file into several different arrays but python gives me an 'out of memory' error

python,out-of-memory,jython
I am attempting to read a .csv file into 7 different arrays. The first array is for the names of the columns and takes the first 6 values of the csv file as the column names are at the begging. After those 6 names have been recorded in the array...

Location of python source code in Jython/Java integration

java,python,integration,jython
I could integrate the java/jython from this source. I downloaded the jython with brew, so the jar file is located in /usr/local/Cellar/jython directory. I came up with the following script to build the class file into the _build directory, but the issue is that I had to copy the python...

How to make one list without a sublist from a string in Python

python,jython
I'm trying to create a list without any sublists from a string with white space in Python? For example: s = "Hello world" L = s.split() print L >>>> ["H","e","l","l","o"," ","w","o","r","l","d"] What I want to avoid it this: s = "Hello world" L = s.split() print L >>>> ["Hello", "world"]...

Pass a variable from Jython (wsadmin) to shell script

linux,shell,jython,wsadmin
I am trying to pass a value retrieved from WebSphere using a Jython script called by wsadmin.sh to a variable in my caller shell script. The caller shell script (getValue.sh) would have: #!/bin/sh /opt/ibm/WebSphere/AppServerV70/bin/wsadmin.sh -lang jython -conntype SOAP -f /home/user/Jython.py exit 0 The Jython script (Jython.py) would have: cellName =...

Does Jython have a 'startup file' like Python?

python,jython
Jython 2.7b2 does not respect PYTHONSTARTUP, nor does it respect JYTHONSTARTUP. If there is no such thing in Jython, what would be a good workaround?

Jython 2.7b4 will not webstart: ImportError: No module named site

jython,java-web-start
I injected my application into jython-standalone-2.7-b4.jar. Here is what I see in the webstart console of the client machine when I webstart my app: Java Web Start 11.31.2.13 Using JRE version 1.8.0_31-b13 Java HotSpot(TM) 64-Bit Server VM User home directory = C:\Users\me ... #### Java Web Start Error: #### null...

How do I fix UnsupportedCharsetException in Eclipse Kepler/Luna with Jython/PyDev?

java,python,eclipse,pydev,jython
Example code: from java.lang import System if __name__ == '__main__': [System.out.print(x) for x in "Python-powered Java Hello World from within a List-Comprehension."] Annoying output: console: Failed to install 'org.python.util.JLineConsole': java.nio.charset.UnsupportedCharsetException: cp0. console: Failed to install 'org.python.util.JLineConsole': java.nio.charset.UnsupportedCharsetException: cp0. Python-powered Java Hello World from within a List-Comprehension. I've tried the solution...

Passing java object to python

java,python,jython
I am prototyping an interface to our application to allow other people to use python, our application is written in java. I would like to pass some of our data from the java app to the python code but I am unsure how to pass an object to python. I...

How to use “jython-standalone-2.7-b3.jar” in windows 7?

python-2.7,jython,jython-2.5,jython-2.7
I want to upgrade Jython from "jython2.5.4rc1" to "Jython 2.7-beta3". I have downloaded following two files from "http://www.jython.org/downloads.html": 1. Jython 2.7beta3 - Installer - jython-installer-2.7-b3.jar 2. Jython 2.7beta3 - Standalone Jar - jython-standalone-2.7-b3.jar When I doubleclick on "jython-installer-2.7-b3.jar" file, I am getting "Could n ot find the main class:org.python.util.install.Installation.program will...

Error when calling Native Code using JNI from a Jython module

eclipse,jni,jython
I am calling a simple HelloWorld program written in C from a Jython module (inside a PyDev project). There is an intermediate Java Class (in a separate Java project) which calls the native code using JNI (Java Native Interface). The native call is successful if I run the Java class...

trap exceptions comprehensively in Jython

exception,exception-handling,jython,throwable
This is my attempt so far to trap all exceptions in Jython code. The most difficult thing, I find, is trapping exceptions when you override a method from a Java class: with the "vigil" decorator below (which also tests whether the EDT/Event Despatch Thread status is correct) you can find...

Jython command terminating batch scripts

python,cmd,jython
In a directory I have three files. test.py, containing print "Hello World" python_runner.bat, containing python test.py PAUSE jython_runner.bat, containing jython test.py PAUSE The python_runner.bat works as expected, but running Jython_runner.bat causes the PAUSE command to be skipped! Why is Jython causing the batch script to be prematurely terminated? (NOTE: I...

Eclipse RCP and Jython

eclipse,pydev,jython,rcp
I'm writing an eclipse RCP application and want to integrate Jython with it. I'm already able to launch the pydev python console using the Console view and choosing PyDev -> Python console. But when trying to launch Jython I get a series of exceptions: Jython does work in my Eclipse...

Wrapping a string in a File object in Jython

java,jython
I'm trying to do some XML DOM manipulations in an embedded Jython interpreter that doesn't have access to substantial portions of the standard library. To that end, I'm hoping to make use of the java standard library (to which I have access) and utilize org.w3c.dom, the DocumentBuilderFactory, or similar. The...

Accessing winreg from jython

python,jython,winreg
Why can't access the _winreg module from jython? c:\>python Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. import _winreg c:\>jython Jython 2.7b1 (default:ac42d59644e9, Feb 9 2013, 15:24:52) [Java HotSpot(TM) 64-Bit Server VM (Sun Microsystems Inc.)]...

Spring-integration scripting with Python

python,spring-integration,jython
I'm trying to use Python with spring-integration and jython-standalone-2.7.0: Here is my application context: <int:inbound-channel-adapter id="in" channel="exampleChannel" > <int:poller fixed-rate="1000" /> <int-script:script lang="python" location="script/message.py" /> </int:inbound-channel-adapter> <int:channel id="exampleChannel" /> <int-ip:udp-outbound-channel-adapter id="udpOut" channel="exampleChannel" host="192.168.0.1" port="11111" /> Here is my script in Python: print "Python"...

Using NumPy with JyNI

python,numpy,jython
I am trying to use a Python program with Java. My Python program is as follows: import CostCalculatorType import os from Evaluate.read_input_data import * class CostCalculator(CostCalculatorType, object): def __init__(self): print 'Initializing' pass def calculateCost(self, chromosome): inputData = ReadInputData(chromosome, 'input_data.txt') return inputData I am calling this from a Java interface. I...

How to use for-loop in Jython PythonInterpreter?

python,for-loop,jython
Is it possible and how to write down for-loop in PythonInterpreter using exec() method? With exec() it looks fine and like interactive line by line input in the Python command line, but the following with for statement doesn't work: PythonInterpreter python = new PythonInterpreter(); python.exec("import sys"); python.exec("for p in sys.path:");...

Importing flask module in jython jar

java,python,jar,flask,jython
This is my first attempt at working with jython, so here goes! I've got a little Python app using Flask as my web framework, and I want to package it up into a jar. I've followed the jar method tutorial here, and I've got my app components all set inside...

Python/Jython parse e-mail

python,jython
I have parsed en e-mail message using Jython to get the e-mail mesages body value. Now I have the body value and I'd like to extract the following text from it. The body contains text and I would like to extract the following text: There are rows found in the...

How do I add a variable's value to a picture in JES/ Jython? [closed]

python,image,variables,jython,jes
As per the topic, How do I add a variable's value to a picture? I have an image I want to add a variable's value to, and prefferably a word before and/ or after. The question's topic may be answerable from Jython/ Python knowledge as they sometimes work the same...

Java/Jython - how to relate unfound classes to specific jar files

java,class,jython,packages
This also puzzled me when experimenting with the Lucene package... but this is an example now I'm trying to get into HTTP/JSON/URL stuff using Java. In fact I use Jython... as this is not an SSCCE I've left it in the (more concise) Jython. Java users should have no difficulty...

JYTHON Calculating the number of pixels in a picture

python,image,jython,pixels
Working on a program that can calculate the number of black,white or red pixels in a room. (ill use black for the example) I've tried to get this to work but I cant for the life of me. Assume that all of my mediapaths have already been set. i =...

Saving a picture in Python

python,image,file,save,jython
In Python I have created a picture using the "makeEmpyPicture" function in Python. How do I save this as an external file. I have a string that I want to call it. All I want to do is to be able to save it without importing any libraries into my...

How to execute if statement using Jython

java,python,jython
import org.python.util.PythonInterpreter; public class JythonTest { public static void main(String[] args) { PythonInterpreter interp = new PythonInterpreter(); interp.exec("if 2 > 1:"); interp.exec(" print('in if statement!'"); } } I need to be able to execute Python code from a Java program, so decided to try out Jython, but I'm unfamiliar with...