3.2.3. Program

The Program node can implement some custom logic through a portion of Python or JavaScript code.

Input

The Program node can also add the number of input elements. After customizing the names of the elements, you can choose Quote to call the variables of the previous nodes, or choose Customize to select a type from the following types and customize the value of the element.

Element Type Description
String String type, a string is a special object that belongs to the reference type and includes operations for processing sequences of characters.
Integer Used to represent integers, it can store integer values, including positive integers, negative integers, and zero.
Float A floating-point number is a numerical data type used to represent decimals and fractions. Floating-point numbers can represent a wider range of numerical values than integers, including very small and very large values.
Boolean Used to represent the logical states of true (True) and false (False).
Timestamp A data type used to represent a specific point in time, usually calculated in seconds or milliseconds from a starting time. It is used to record the time of events, sort data, calculate time differences, etc.

Code

The Code node provides two programming methods: Python and JavaScript. Users can write a method (the code block can only contain one function) to process the input data and output elements.

def main(args):
    a = args["a"]
    b = args["b"]
    return {"aa": a, "bb": b}

In the default code, args is a list that contains the elements input by Input. The return {} represents a dictionary (dict) where "aa" corresponds to the element name in Output, and a represents the output value of Output "aa".

Note: Third-party libraries cannot be used in the Program node. Currently, only built-in commands and json can be used, and the default timeout for running the Program node is 5 seconds. If the Program node runs for more than five seconds, it will fail to run and return a timeout.

Output

Therefore, when setting Output, the element names must correspond to those in the Code, and the element types must also match. Be careful if there are any type changes in the defined method, and pay attention to the input types of the elements. Errors in element names or types when setting Output will cause Copilts to fail to run (returning multiple elements but not outputting all is feasible).

results matching ""

    No results matching ""