Example of using Python script to join a list

Build a bot that uses a Python function to print the message Go Be Great!, the Automation Anywhere version of Hello World. In this example, the bot combines a list of string values and prints them to a message box.

Prerequisites

To run Python script from Automation 360, you must already have the latest version of Python 3.x installed on your device.

Procedure

  1. Create a new bot:
    1. On the left panel, click Automation.
    2. Click Create new > Bot.
    3. In the Create Task Bot window, enter the bot name.
    4. Accept the default folder location: \Bots\
      To change the default bot storage location, click Choose and follow the prompts.
    5. Click Create and edit.
  2. Create a variable to hold the list values:
    1. Click the Create variable icon.
    2. Enter lArgument in the Name field.
      Recommendation: Prefix the variable name with a lowercase character to indicate the variable data type.

      Variable naming

    3. Select the List type and String subtype.
    4. In the Default value field, enter the following values:
      1. Value at 0: Go
      2. Value at 1: Be
      3. Value at 2: Great
      4. Value at 3: !
    5. Click Create.
  3. Provide the script with a Python Script > Open action:
    1. Double-click or drag the Python Script > Open.
    2. Select the Manual input option.
    3. Copy and paste the following text into the Enter script here field.
      def data ( str ):
          x = " ".join( str )
          return x
  4. Use a Python Script > Execute function action to tell the bot to run the script:
    1. Double-click or drag Python Script > Execute function.
    2. Enter data in the Enter name of function to be executed field.
    3. Select the lArgument variable from the Arguments to the function drop-down list.
    4. Create the variable sOutput for the Assign the output to variable field.
  5. Insert a Message box action to hold the Python function output:
    1. Double-click or drag the Message box > Message box action.
    2. In the Enter the message to display field, select and insert the variable sOutput.
    3. Select the Close message box after option. Retain the default value of 5 seconds in the field.
  6. Close the script execution session with a Python Script > Close action:
    1. Double-click or drag Python Script > Close.
    2. Click Save.
  7. Click the Run icon.
    The bot generates a message box with the text Go Be Great!. After 5 seconds, the message box disappears.

    To review the bot launcher logs, navigate to C:\ProgramData\AutomationAnywhere\BotRunner\Logs\<current month>\Bot_Launcher-<today's date>.log.zip. Each zipped folder contains a file with data on the code execution, which is useful for debugging.