The python code block can be used with its own code or code loaded from another source as a text editor with the type
This block allows multiple inputs and outputs. This makes it interesting to tie the behaviors of different blocks together.
To set the inputs and outputs for the script, select "open extended view" which opens a popup.
A Python file or the user can directly write the code. Moreover in the extended view below it is possible to define input variables.
Imagine we have the following Python script:
You can see that
b are not defined in this script.
On the top right you can set the inputs. Enter the variable name
a and accept it with the
+ button. You can now choose any channel from your post. Repeat this with
b. Input variables can be deleted with
x next to the import.
Outputs can be defined on the bottom left. Enter
sum into the text field and accept ith with
+. Now, choose a content type. For simple values as arrays or numbers,
JSON is the best option.
Like inputs, output variables can be deleted with
Add a description above the code block.
The block can be hidden from readers but its content is still available as input for other blocks. You can hide it only if you set it to execute automatically.
The script will run automatically on load and any input change. If set to false, the script will have to be run explicitly.
Python blocks can be set to publicly editable. This may be interesting if you want to show calculations depending on certain parameters. After a page reload the changes in the code will be lost.
Python Code Block using Pyodide on inseri.swiss.
Posts on inseri.swiss that make use of the Python code block.