Defining Parameters in Python

Define parameters in Python by assigning values to top-level variables—these become accessible throughout your CalcTree page.

In CalcTree, parameters are the core building blocks of a calculation. For Python sources, parameters are defined as top-level variables—any variable assigned at the root level of the script (i.e. not inside a function or class).

These variables are automatically extracted and added to the page's parameter list on the right-hand panel, and can be added to the page as parameters that reference the Python parameter

Example

Defining the following in a Python source will create a parameter.

a = 2

After a short moment, a will appear as a parameter under the Python source. Its value can be referenced by other sources or reused across the page.

Notes

  • Only variables defined at the top level of the script are treated as parameters

  • Variables inside functions or conditional blocks will not be extracted

  • Parameters can be scalar values, arrays, quantities with units, or tables (nested lists)

Last updated