Execute script action

The Execute script action in the Python Script package enables you to execute a script within the Python Script package.

Settings

  • In the Python session field, specify a session name. Use the same session name from the Open action.
  • Optional: In the Assign the output to variable field, specify the string variable.

    If the bot executes the script successfully, this action returns the string True. Otherwise an error message appears.

The following example shows the difference between the Execute Script and Execute function actions.

When you open a new Python session, you provide a Python script or file. The script might contain a few lines of code to be executed or might contain a file of functions used to perform certain operations, such as:

#executable code flow
file = open("abc.txt", "w")
file.write("Some text")
file.close()


#functions, not in executable flow
def function1():
  return 9+10

def function2():
  return "Some Text"

def add(a,b):
  return a+b
  • When you use the Execute script action, it will only execute the lines of code in the executable flow of the script. Any functions that are defined but not called will not be executed.
  • When you use the Execute function action, the session can call any function in the script or file, and provide the arguments required for the function while storing the returned values in a variable.