Python variables

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

In CalcTree, variables are the core building blocks of a calculation. For Python nodes, variables 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 variables list on the right-hand panel, and can be added to the page as mentions.

Example

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

a = 2

After a short moment, a will appear as a variable in the variables list and under the Python Node in the Nodees tab. Its value can be referenced by other nodes or reused across the page.

Notes

  • Variables inside functions or conditional blocks will not be extracted

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

Last updated