Variables in Python Steps
This page explains how to use variables defined in a Python script step in subsequent steps.
In a workflow, candidate variables that can be used are shown in each step's input fields,
but variables defined inside Python code are not shown among these candidates.
To use such variables in later steps, there are two methods:
| Method | Use case |
|---|---|
| Pass via an internal variable | When you want to reuse the same value across multiple steps |
| Enter directly into the input field | For temporary calculation results that are not reused by other steps |
Pass via an internal variable
Predefine a workflow internal variable and assign a value to that internal variable in your Python code.
The internal variable will then appear as a candidate in the input fields of subsequent steps so you can select it.
- Define the variable name you want to pass as a workflow internal variable in advance.
For detailed instructions, see "Inputs and outputs: defining internal variables". - In the Python script step, assign a value to that internal variable.
# Predefine an internal variable named resultresult = price * quantity
The input fields of subsequent steps will show result as a candidate.
This method is suitable when you want to reuse the same value across multiple steps.
Because variables are managed explicitly across the workflow, it makes the data flow easier to follow.
Enter directly into the input field
You can also reference a variable without defining it as an internal variable by writing {{ variable_name }} directly in the input field of a later step.
Although it won't appear among the candidates, you can reference it if you know the variable name.
{{ subtotal }}
Because it does not appear in the candidates, be careful that a typo in the variable name may go unnoticed.
This approach is suitable for temporary calculation results that are not reused by other steps.