Advanced Expressions
This page continues Values, Variables & Expressions, which covers the everyday cases.
The field also accepts calculations, text manipulation, date handling and conditions. The
notation is Python; variables are still marked with $.
Reaching into data
When a variable holds a list or a dictionary, square brackets get you inside. After you type
[, the auto-completer offers the keys or positions directly.
| You type | Result |
|---|---|
$items[0] | apples — first element, counting from zero |
$items[-1] | plums — last element |
$record['state'] | OK — value by key |
$record['id'] | 7 |
$name[0:3] | Jan — first three characters |
The same notation slices a list.
Working with text
Write a dot after the variable and the name of an operation:
| You type | Result |
|---|---|
$name.upper() | JAN NOVÁK |
$text.strip() | Invoice 2024 — trims leading and trailing spaces |
$name.replace('Novák', 'Nový') | Jan Nový |
$date.split('.') | ['01', '02', '2024'] |
", ".join($items) | apples, pears, plums |
$text.strip().lower() | invoice 2024 — operations chain |
Functions
The General and Math tabs of the auto-completer list what is available, each with a description and an example.
| You type | Result |
|---|---|
len($items) | 3 — number of elements |
len($name) | 9 — number of characters |
int($amount) | 1250 |
str($count) | 3 — as text |
round($amount) | 1250 |
max($count, 10) | 10 — larger of the two; min likewise |
sum([1, 2, 3]) | 6 |
abs(-5) | 5 |
Lists, dictionaries and tuples
Useful when you need to pass several values at once — into a form, or on to another action.
| You type | Result |
|---|---|
[$name, $count] | ['Jan Novák', 3] — list |
{id:$count, name:$name} | {'id': 3, 'name': 'Jan Novák'} — dictionary |
($count, $amount) | (3, 1250.5) — tuple |
Key names need no quotes. After reopening you see them quoted — {'id':$count, …} — which
is the same thing.
Mind the difference: $count, $amount with nothing else is a tuple, whereas
We have $count for $amount CZK is text.
Date and time
A date stored as text must first be parsed with datetime_parse and then rendered with
datetime_format.
| You type | Result |
|---|---|
datetime_parse($date, '%d.%m.%Y') | the date read from the text |
datetime_format(datetime_parse($date, '%d.%m.%Y'), '%Y-%m-%d') | 2024-02-01 |
datetime_format(datetime.datetime.now(), '%d.%m.%Y') | today's date |
datetime_format(datetime_add(datetime.datetime.now(), days=7), '%d.%m.%Y') | the date a week from now |
| Helper | What it takes |
|---|---|
datetime_parse(text, format, tz=None) | Reads a date out of text. |
datetime_format(date, format) | Renders a date as text. |
datetime_add(date, …) | Shifts a date by days, hours, minutes, seconds, microseconds, months or years. |
datetime_set(date, …) | Sets a specific part — day, month, year, hour, minute, second, microsecond. |
Format codes: %d day, %m month, %Y four-digit year, %H hour, %M minute.
Constants and system values
The Constants tab holds ready-made values; picking one inserts the whole expression.
| You type | Result |
|---|---|
datetime.datetime.now() | current date and time |
int(datetime.datetime.now().timestamp()) | seconds since the epoch, e.g. 1785841813 |
random.randint(0, 1000000) | a random number |
$CONSTANTS['FULL_DATE'] | a scenario-wide constant — see the full list |
chr(10) | a line break — offered in the tab as newline |
chr(9) | a tab character — offered in the tab as tab |
Modules
Six modules are available: re, math, random, datetime,
pathlib and aiviro.
| You type | Result |
|---|---|
re.sub('[0-9]', '', $text) | ' Invoice ' — strips all digits |
math.ceil($amount) | 1251 — rounds up |
random.randint(1, 100) | a random number from 1 to 100 |
Number bases
| You type | Result |
|---|---|
bin($count) | 0b11 |
hex($count) | 0x3 |
oct($count) | 0o3 |
int("1100", 2) | 12 — from binary text back to a number |
Operators
Every operator below is also in the Operators tab of the auto-completer, with a description.
Arithmetic
| You type | Result | Meaning |
|---|---|---|
$amount + $count | 1253.5 | add |
$amount - $count | 1247.5 | subtract |
$amount * $count | 3751.5 | multiply |
$amount / $count | 416.833… | divide — result is a decimal |
$amount // $count | 416.0 | integer division |
$amount % $count | 2.5 | remainder — handy for odd/even tests |
$count ** 2 | 9 | power |
Joining and repeating
+ and * work on text and lists too — there they join and repeat rather than add.
| You type | Result |
|---|---|
$items + ["berries"] | ['apples', 'pears', 'plums', 'berries'] |
"-" * 20 | -------------------- — a separator |
You do not need + to build text from variables — just write the sentence and mark the
variables with $.
Comparison
Used mostly in Condition and loop actions, where the Editor asks "should this run?". The
answer is True or False.
| You type | Result | Meaning |
|---|---|---|
$amount > 1000 | True | greater than; < is less than |
$count <= 3 | True | less than or equal; >= likewise |
$record['state'] == "OK" | True | equals — note the two equals signs |
$name != "Petr" | True | does not equal |
Logic
| You type | Result | Meaning |
|---|---|---|
$amount > 1000 and $count > 1 | True | both must hold |
$amount > 5000 or $count > 1 | True | at least one must hold |
not $note | True | negation — holds when the value is empty |
$count > 1 and $count < 10 | True | a range |
Empty text, zero and an empty list count as "no"; anything filled in counts as "yes".
Contains / is inside
| You type | Result |
|---|---|
"apples" in $items | True |
"bananas" not in $items | True |
"state" in $record | True — does the dictionary have that key? |
"Novák" in $name | True — substring search in text |
$note is None | False — empty text is not the same as None |
Two useful tricks
| You type | Result |
|---|---|
$note or "not filled in" | not filled in — a fallback when the variable is empty |
len($items) > 2 | True — a condition built on a function's result |
One-line conditions
For a simple "if yes then A, otherwise B", write the condition straight into the field — typically in Create variable.
| You type | Result |
|---|---|
"VIP" if $amount > 1000 else "standard" | VIP |
$name if $name else "unknown customer" | Jan Novák, or unknown customer if $name were empty |
Transforming and filtering a list
One line can walk a list and change or filter each item.
| You type | Result |
|---|---|
[i.upper() for i in $items] | ['APPLES', 'PEARS', 'PLUMS'] |
[i for i in $items if i != 'pears'] | ['apples', 'plums'] |
len([i for i in $items if i != 'pears']) | 2 |
i is just a helper name for one item — it takes no $.
Without the square brackets the same construction is a generator expression. It is useful
inside functions such as any(), all() or sum(), which only need to look at the items
one by one:
| You type | Result |
|---|---|
any(i.endswith('s') for i in $items) | True — at least one item ends with s |
sum(len(i) for i in $items) | 16 — the item names have 16 letters in total |
F-strings
An f-string is text with values substituted in, what used to be written as
f"text {variable}". You no longer need to write it: type the text and mark variables with
$, and the Editor builds the f-string itself.
| You type | Result |
|---|---|
Record $name cannot be processed | Record Jan Novák cannot be processed |
f"Hello {name}" | Hello Jan Novák |
Written by hand it works too. Inside the braces, though, no $ — {name} is right,
{$name} is not. After reopening you see the simpler form, Hello $name.
Older scenarios containing f-strings keep working and open correctly.
When to reach for Python Code instead
The value field is meant for one value on one line. As soon as you need several steps in sequence, loops, error handling or longer logic, use the Python Code action — there you get a full editor and the code stays readable.