Code Node
The Code node allows you to write Python code to process complex logic such as text and generate expected return values.
The Code node is an optional node. If it does not need to be configured, skip this section.
To configure the Code node, perform the following steps:
- Drag the Code node on the left to the canvas and click the node to open the node configuration page.
- Configure the Code node by referring to Table 1.
Table 1 Code node configuration Configuration Type
Parameter Name
Description
Parameter configuration
Input params
Configure the input parameters required for code running.
- Param name: The value can contain only letters, digits, and underscores (_), and cannot start with a digit.
- Type and Value: Type can be set to ref and literal.
- ref: You can select the output parameters of the previous nodes contained in the workflow.
- literal: The value can be customized.
Output params
Configure parameters that need to be output after the code is executed. The parameters must be the same as those returned by return.
- Param name: The value can contain only letters, digits, and underscores (_), and cannot start with a digit.
- Param type: output parameter type. The options are String, Integer, Number, Boolean, and more.
- Description: description of the output parameter.
- Required: whether the current output parameter is mandatory.
Code
-
You can compile Python code snippets. Only the Python system library is supported, and dependency packages cannot be imported. The following is an example of code configuration:
- Sample code for text stitching
def main(args: dict) -> dict: # Define a variable named input1 in the input parameters. input1 = args.get('input1') # Define a variable named input2 in the input parameters. input2 = args.get('input2') res = { # Define a variable named res in the output parameters. "res": input1 + input2, } return res
- Sample code for mathematical calculation
def main(args: dict) -> dict: # Define a variable named input1 in the input parameters. input1 = args.get('input1') try: input1 = int(input1) return { # Define res in the output parameters. 'res': input1 * input1 } except Exception as e: return { # Define res in the output parameters. 'res': "The input type is incorrect or the number exceeds the upper limit." }
NOTE:Do not change the function definition in the first line when writing code.
Figure 1 Code node configuration example - After completing the configuration, click OK.
- Connect the Code node to other nodes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot