Sidebar

Home



Expressions V4


Tutorials

How-To

Reference

  Lexical basics
  Type system
  Variables and assignment
  Operators
  Expression rules
  Control flow
  Functions
  Built-in functions
   None and NaN
   Arithmetic
   Algebra
   Logarithmic and Exponential
   Trigonometric
   Rounding and Centering
   Strings
   Output, Formatting, and Errors
   Dialogs, Clipboard, Platform, and Paths
  Methods and properties
  Built-in methods
   Common Value Methods
   Number Methods
   String Basic Methods
   String Slice Methods
   String Parsing Methods
   String Formatting Methods
   String Regex Methods
   String Trim and Case Methods
  Objects
  Built-in objects
   Global objects
    settings
    session
    python
   Collections
    array
    map
    data_array
   File Format I/O
    image_data
    image_stream
   Utils
    crypto
    timer
   Comm
    serial
   Dialogs
    file_open
    file_save
    msg_ok
    msg_ok_cancel
    msg_yes_no
    msg_password
   GUI objects
    window
    panel
    group
    splitpanel
    label
    textbutton
    drawablebutton
    togglebutton
    togglegroup
    textinput
    textedit
    numinput
    slider
    combobox
    listbox
    progressbar
    led
    separator
    menu
    image
    snake
  Classes and user-defined objects
  Include system
  Error model
  Execution model and sessions
  Host integration
  Limits and performance
  Formal reference
  Glossary

Cookbook

exprv4:reference:objects:python


python

`python` is a built-in global object for running Python code from Expr.

It is used directly by name. Do not call `python()`.


Methods

eval(expression)

Evaluates a Python expression string and returns the converted result.

value = python.eval('2 + 3 * 5');
print(value);        // 17

run_code(code)

Runs Python code synchronously and returns the Python script result.

result = python.run_code('result = 40 + 2');
print(result);       // 42

run_code(code, params)

Runs Python code synchronously with parameters from a `map`.

result = python.run_code('result = a + b', map('a', 10, 'b', 20));
print(result);       // 30

run_file(filePath)

Runs a Python file synchronously and returns the Python script result.

result = python.run_file('scripts/example.py');

run_file(filePath, params)

Runs a Python file synchronously with parameters from a `map`.

result = python.run_file('scripts/example.py', map('a', 10, 'b', 20));

code(code)

Creates a `python_task` object for asynchronous execution of Python code.

task = python.code('result = 7');
task.run();

code(code, params)

Creates a `python_task` object for asynchronous Python code execution with parameters.

file(filePath)

Creates a `python_task` object for asynchronous execution of a Python file.

file(filePath, params)

Creates a `python_task` object for asynchronous Python file execution with parameters.


python_task

`python_task` is returned by `python.code(…)` and `python.file(…)`.

Properties:

Property Type Description
`started` boolean `true` after `run()` has been called.
`running` boolean `true` while the Python task is running.
`completed` boolean `true` after the task finishes.
`ok` boolean `true` when the task completed successfully.
`use_subinterpreter` boolean Current sub-interpreter setting.
`result` any Result returned by the Python script.
`error` string or none Error text when the task failed.
`event_count` number Number of queued events from Python.

Methods:

Method Returns Description
`on_complete(callback)` boolean Sets a callback called with `ok` and `result`.
`on_event(callback)` boolean Sets a callback called with event name and value.
`use_subinterpreter(enabled)` boolean Sets sub-interpreter use before `run()`.
`run()` boolean Starts the task. A task can be run only once.
`read_event()` map or none Reads the next queued event.
`send_command(name, value)` boolean Sends a command to the running Python script.
`terminate()` boolean Requests termination of the running Python script.

Example:

task = python.code('result = 123');
task.run();
while (!task.completed) {}
print(task.result);

Previous: session

Next: Collections

exprv4/reference/objects/python.txt · Last modified: by 127.0.0.1

Page Tools