Icon

Script Throwing 2022-11-28 PA1

A script entered as a multi-line text string can be pickled and forwarded to other nodes; where it is compiled andexecuted. This allows KNIME developers to create Python libraries which can be imported at runtime into othernodes, reducing code replication within a workflow.Node 1, the standard ports are removed and a Output Object (Pickled) port is added.Nodes 2, 3 a Input Object (Pickled) port is added. In node 1, the script is entered as mulit-line string and passed to the Output Port (Pickled). Note, it is important topay attention to Python indentation in the string as this may case errors when it is compiled and evaluated.In the receiver nodes (2, 3) the string is read from the Input Object (Pockled) port and then compiled and evaluated`eval(compile(script, "<string>", "eval"))`. The parameter "<string>" identifies the script type as a string, and "eval"indicates that the string should be compiled. Evaluate will then run the code as if it was entered in the receivernode.EXAMPLEOpen node 1. The script defined in the text string prints a message in the receiver node. It does not execute in theoriginating node, but will be communicated to the receiving nodes.Open nodes 2, 3. Execute the script. You will see the message entered in node 1 printed in the output console. Node 1Node 2Node 3 Python Script Python Script Python Script A script entered as a multi-line text string can be pickled and forwarded to other nodes; where it is compiled andexecuted. This allows KNIME developers to create Python libraries which can be imported at runtime into othernodes, reducing code replication within a workflow.Node 1, the standard ports are removed and a Output Object (Pickled) port is added.Nodes 2, 3 a Input Object (Pickled) port is added. In node 1, the script is entered as mulit-line string and passed to the Output Port (Pickled). Note, it is important topay attention to Python indentation in the string as this may case errors when it is compiled and evaluated.In the receiver nodes (2, 3) the string is read from the Input Object (Pockled) port and then compiled and evaluated`eval(compile(script, "<string>", "eval"))`. The parameter "<string>" identifies the script type as a string, and "eval"indicates that the string should be compiled. Evaluate will then run the code as if it was entered in the receivernode.EXAMPLEOpen node 1. The script defined in the text string prints a message in the receiver node. It does not execute in theoriginating node, but will be communicated to the receiving nodes.Open nodes 2, 3. Execute the script. You will see the message entered in node 1 printed in the output console. Node 1Node 2Node 3Python Script Python Script Python Script

Nodes

  • Python Script3 ×

Extensions

  • No modules found

Links