Jython error - padding number string

Good morning all. I get a generic error when trying to run the following code. Can anyone point out where I’m going wrong?

I have a string with numbers that must be ‘0’ left-padded to 9 characters. So, if the number is 123, the string should be ‘000000123’. Just to clarify: I’m using the “JPython Script 1:1” node. Additionally, when I try this in my command line jython, it works.


dts = inData0.getDataTableSpec()
inputColumnIndex= dts.findColumnIndex(“NbrStrInput”)
iterator = inData0.iterator()
while iterator.hasNext():

    row = iterator.next()
    cell = row.getCell(inputColumnIndex)
    nbrstr = str(cell) #I tried this without attempting to convert to str and received the same result.
    dist = 9 - len(nbrstr)
    i = 0
    if dist > 0:
      while i < dist:
        i += 1
        nbrstr = ‘0’ + nbrstr

    newRow = AppendedColumnRow(row, [nbrstr])
    outContainer.addRowToTable(newRow)

Have you configured the output table spec correctly (there is a separate tab, in which you specify which columns your code is going to append). If you can’t find errors in there, I suggest that you look into the log file if it contains a detailed error message. The log file location is printed in the “Console” view when you start knime (<workspace>/.metadata/knime/knime.log).

Hope this helps,
Bernd

Thanks for the response. Yes, the output is configured to be a single field of String type. The output console reads, “ERROR JPython Script 1:1 Execute failed: Jython error (see console for error log).”, which is not all that helpful.

The log does help (thanks):
TypeError: org.knime.base.data.append.column.AppendedColumnRow(): 2nd arg can’t be coerced to org.knime.core.data.DataCell[]

Based on that, I used newRow = AppendedColumnRow(row, [StringCell(nbrstr)]) and that seems to work.

Thanks for the help.