JPython Script 1:1

Hi,
I'm new to Knime and JPython. I'm using the JPython Script 1:1 node to add a column to a table. I'm using the script below:

iterator = inData0.iterator()
while iterator.hasNext():
row = iterator.next()
newStringCell = StringCell("some string")
newRow = AppendedColumnRow(row, newStringCell)
outContainer.addRowToTable(newRow)

In the StringOutput dialog I've added an Output Column of type 'String'

I get the following error in the console:

ERROR PythonScriptNodeModel
ERROR JPython Script 1:1 Execute failed
ERROR JPython Script 1:1 Jython error (see console for error log).

I'm confused by the (see console for error log). Is there another console which I should be looking at for errors?

Can someone help me get this to work?

Thanks for the help,
Liisa

Hello Lisa,

actually you are looking at the correct console, but you need to activate the DEBUG-level iin order to see the full error message exception that occurs when the Python node tries to parse your script.
In the Menu click on Window->Preferences->KNIME and set the Console Log Level to DEBUG. If you execute the node again you should have an error message like this:

java.lang.Exception: Jython error (see console for error log).
	at org.knime.ext.jython.PythonScriptNodeModel.execute(PythonScriptNodeModel.java:257)
	at org.knime.core.node.NodeModel.execute(NodeModel.java:298)
	at org.knime.core.node.GenericNodeModel.executeModel(GenericNodeModel.java:371)
	at org.knime.core.node.Node.execute(Node.java:674)
	at org.knime.core.node.workflow.SingleNodeContainer.executeNode(SingleNodeContainer.java:514)
	at org.knime.core.node.workflow.SingleNodeContainer.access$1(SingleNodeContainer.java:505)
	at org.knime.core.node.workflow.SingleNodeContainer$1.run(SingleNodeContainer.java:403)
	at org.knime.core.node.workflow.JobRunnable.run(JobRunnable.java:41)
	at org.knime.core.node.workflow.ThreadedJobExecutor$Worker.run(ThreadedJobExecutor.java:75)
Caused by: Traceback (innermost last):
  (no code object) at line 0
SyntaxError: ('invalid syntax', ('<>', 27, 1, 'row = iterator.next()'))
at org.python.core.parser.fixParseError(parser.java)
at org.python.core.parser.parse(parser.java)
at org.python.core.Py.compile_flags(Py.java)
at org.python.core.Py.compile_flags(Py.java)
at org.python.core.__builtin__.compile(__builtin__.java)
at org.knime.ext.jython.PythonScriptNodeModel.execute(PythonScriptNodeModel.java:251)

which telly sou that something went wrong in the line with row=iterator.next().

I am not very familiar with Python, but every statement that should be executed in a while- loop needs to be indented.
You also need to pass a DataCell-array to the second argument of the constructorof AppendedColumnRow by putting the StringCell into [] brackets.

The correct script should look like this:

iterator = inData0.iterator()
while iterator.hasNext():
	row = iterator.next()
	newStringCell = StringCell("some string")
	newRow = AppendedColumnRow(row, [newStringCell])
	outContainer.addRowToTable(newRow) 

Best regards

Nicolas

Thanks Nicolas! Working fine now!

This post is old, but I have basically the same problem, the JPython Script 1:1 node fails, the message in the console says to "see console for error log", but unfortunately there is nor more information, even if the DEBUG mode is activated.

 

Could you, please, tell me what to do?