Run Python Code
Command description
- Runavelo converts a workflow into Python code before executing it. Code entered here is inserted at the corresponding position in the generated source.
- You can run Python statements, define classes or functions, call functions, and use third-party libraries. The code remains available when the workflow is exported and imported on another computer, provided its dependencies are available.
- Runavelo handles indentation relative to the workflow position.
- The inserted code can read and write Python variables from the workflow.
Command Input Parameters
| input parameters | Input parameter type | Description |
|---|---|---|
| Python Code | PythonStatement | Python code |
Command Output Parameters
None
Example 1
The value of in["Python Code"] is inserted directly into the Python source and must not be wrapped in another string literal.
[
{
"children": [],
"in": {
"Browser Type": "'Google Chrome'",
"Match Method": "'Current Webpage'",
"Page Load Timeout": "30"
},
"out": {
"Webpage Object": "web_page"
},
"ins": "Get Open Webpage"
},
{
"children": [],
"in": {
"Python Code": "print(f'{web_page.title} {web_page.url}')"
},
"ins": "Run Python Code"
}
]
Example 2
Seamlessly insert Python code
- Inserted Python code
def cmp(goods):
return goods['count']
ordered_list = sorted(product_list, key=cmp, reverse=True)
- Final generated code
# -*- coding: utf-8 -*-
import sys
from builtin import *
from debuger import call_flow_wrapper
def run(args):
if args:
pass
taobao_page = open_web_page("https://www.taobao.com/", "Google Chrome")
product_list = execute_js(taobao_page, None, "async function (htmlElement, param) {\n const goods = []\n const elements = document.querySelectorAll('.tb-pick-content-item')\n for (let element of elements) {\n const name = element.querySelector('.info-wrapper').innerText\n const price = parseInt(element.querySelector(\".price-value\").innerText)\n const count = parseInt(element.querySelector(\".month-sale\").innerText)\n goods.push({\n name,\n price,\n count\n })\n }\n return goods\n}", "", {"wait":"20"})
# Inserted code - start
def cmp(goods):
return goods['count']
ordered_list = sorted(product_list, key=cmp, reverse=True)
# Inserted code - end
for ____rpa_gen_itr_loop_index, product in enumerate(ordered_list):
print_to_app(product, {"renderHtml":True})
@call_flow_wrapper("main process")
def main(args=None):
return run(args)
View Python code
After the application runs, Runavelo generates Python code at the following location. Open it in File Explorer to inspect the generated code.
- Personal version C:\Users\Your computer username\AppData\Roaming\Runavelo\Personal\User ID\apps\Application name\code
- Enterprise Office C:\Users\Your computer user name\AppData\Roaming\Runavelo\Enterprise\0\apps\Application name\code
For example: C:\Users\young\AppData\Roaming\Runavelo\Personal\2\apps\Sample Application\code C:\Users\young\AppData\Roaming\Runavelo\Enterprise\0\apps\Teaching Example\code
-Building process
- Python code to run
If the generated Python code fails, you can copy it for troubleshooting. Do not edit the generated file directly because it is regenerated every time the workflow runs.
Special reminder
-
The workflow and inserted code execute inside
def run(args), so variables defined by Run Python Code are not global. Use Python'snonlocalkeyword where appropriate, and usetextwrap.dedentto remove unwanted leading spaces from multiline f-strings. -
Each subworkflow corresponds to a
.pyfile. Share values between workflows through global variables:-
Workflow A sets a global variable
-
Workflow B reads or updates the global variable
-