Python Node - Output object (pickled) - Can't pickle functions & code objects problem

Hi,

Python node has the option to pass data formats other than table with object port, however it cannot pass neither

  • a function ( ex: " def my_function(x): return x*x " ) or
  • a code object ( ex: my_function.code )

Object port provides the option to divide a single long python code into smaller parts, however without function passing it is hard to divide the whole code. Thus, some parts still remain long

There are some solutions that apply to regular python interfaces according to the forum

i. one claims using import dill as pickle solves
ii. another one claims In modern Python you can pickle functions, and many variants

If there is a way to perform function pass, can you help me or if there is not a method can you add that ability to the python node?

@ironstone welcome to the KNIME forum

You could put your function into a module and import that into a KNIME/Python node. You would have to do that in every one of them but you only would have to write the function once. You could also feed parts of a Jupyter notebook into KNIME tagging the relevant parts.

Then you can of course save and pickle all sorts of data (1|2|3) but I don’t think custom code and functions can be transfered that way.

I have not yet tested the new Python Script with all the new ports extensively.

3 Likes

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