py()

Executes a Python script or expression within the PlanetCNC environment.

Syntax

py(code)
py(code, use_subinterpreter)

Parameters

Parameter Type Description
code String Python code, an expression, or a file path to execute.
use_subinterpreter Number (Optional) `1` to use a subinterpreter, `0` to run in the main interpreter. Default is `1`. optional

Return Value

Examples

Execute a Python expression

py("2 + 2");  // returns 4

Execute a Python script

py("print('Hello from Python')");

Run a Python file

py("C:/scripts/myscript.py");

Execute Python code using the main interpreter

py("import math\nprint(math.sqrt(16))", 0);

See also

py_list
py
py_term
py_msg