Python Script Table Output

Howdy Knimers,

Im working with the Python Script node and although my code runs and the configuration view of the node shows the right output, I am missing the table output to see it and be able to work with further nodes in KNIME.

The error is “knime user error: output table ‘0’ must be of type knime.api.Table or knime.api.batch output Table but got class ‘list’”

This is my code

import knime.scripting.io as knio

This example script simply outputs the node’s input table.

knio.output_tables[0] = knio.input_tables[0]

numbers = knio.flow_variables[‘Sorted list*(Folio_Import)’]

lowest = min(numbers)
biggest = max(numbers)

print(lowest)
print(biggest)

number_range = range(lowest, biggest+1)
print(list(number_range))

This is how my output looks inside the configuration screen

This is how it errors out from the node itself

Any help is truly appreciated.

@mcrisnidh welcome to the knime forum.

You will have to convert your list to a Pandas dataframe.

https://docs.knime.com/latest/python_installation_guide/#_configuration

Something like this

df = pd.DataFrame(list)
knio.output_tables[0] = knio.Table.from_pandas(df)

Or

df = pd.DataFrame(list)
knio.output_tables[0] = knio.write_table(df)

7 Likes

Thank you for the information. This worked perfectly.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.