Defining a Python function inside a single Python node means that function is only available inside that node.
To create reusable code, your best option is to create a regular Python module, then import that module into each node where you want to use it. Creating a Python module can be surprisingly easy: put your Python functions inside a text file and save it with the file extension ‘.py’.
But what if you are never, ever going to use your Python function again except inside this one Workflow? It might feel like overkill to create a Python module if it only has one place where it ever gets used. You could always copy+paste the function definition into each Python node, but this quickly feels less than ideal.
This workflow demonstrates how a Python function can be defined in one node, then passed along to other Python nodes via a flow variable. If more than one function needs to be propagated along, create another flow variable to hold each function.
To use this workflow in KNIME, download it from the below URL and open it in KNIME:
Download WorkflowDeploy, schedule, execute, and monitor your KNIME workflows locally, in the cloud or on-premises – with our brand new NodePit Runner.
Try NodePit Runner!Do you have feedback, questions, comments about NodePit, want to support this platform, or want your own nodes or workflows listed here as well? Do you think, the search results could be improved or something is missing? Then please get in touch! Alternatively, you can send us an email to mail@nodepit.com.
Please note that this is only about NodePit. We do not provide general support for KNIME — please use the KNIME forums instead.