Run python with result
Run Python with Result is a Developer Function for Developer Edition license users only.
Functions created with run python will run on all editions, but it will only be editable in node view in the Developer edition.
This command will run python functions within UBot Studio and return results. The function is similar to the eval function, in that it will return a value and can be placed in commands that accepts values.
Example 2
set(#bloop, $run python with result("453*65.1"), "Global")
Running the script will set the variable to the results of the calculation.
ui text box("one", #one) ui text box("two", #two) alert($run python with result("{#one}+{#two}"))
In this example, the values being calculated are sourced from variables set to UI text boxes.
We hit the no parse ("") button on the function to keep UBot from parsing the equation using javascript.
Once values are typed into the UI text boxes and the script is run, the end result appears in an alert.
Example 2
In this example, we will be running a python function that calculates and returns the name of the weekday for the date that is provided.
We start by importing the datetime module in the run python with result function.
import datetime
Once the module is imported, the rest of the function is added to set a specific date (1943, 3, 13) we want to use for this calculation.
The python code is returning the day of the week on which the specified date falls on.
import datetime mydate = datetime.date(1985,3, 13) #year, month, day (mydate.strftime("%A"))
The Alert command with the run python with result command will look like the following script:
alert($run python with result("import datetime mydate = datetime.date(1985,3, 13) #year, month, day mydate.strftime(\"%A\")"))
Running the script, we receive the following result through an alert:
The date 1985, 3, 13, falls on a Wednesday.