Example of using Python script to join a list
- Updated: 2021/01/25
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
-
Create a new bot:
- On the left panel, click Automation.
- Click + Create > Task Bot.
- In the Create Task Bot window, enter the bot name.
-
Accept the default folder location: \Bots\
To change the default bot storage location, click Choose and follow the prompts.
- Click Create and edit.
-
Create a variable to hold the list values:
- Click the Create variable icon.
-
Enter lArgument in the
Name field.
Recommendation: Prefix the variable name with a lowercase character to indicate the variable data type.
- Select the List type and String subtype.
-
In the Default value field, enter the following
values:
- Value at 0: Go
- Value at 1: Be
- Value at 2: Great
- Value at 3: !
- Click Create.
-
Provide the script with a Python Script > Open
action:
- Double-click or drag the Python Script > Open.
- Select the Manual input option.
-
Copy and paste the following text into the Enter script
here field.
def data ( str ): x = " ".join( str ) return x
-
Use a Python Script > Execute function
action to tell the bot to run the script:
- Double-click or drag Python Script > Execute function.
- Enter data in the Enter name of function to be executed field.
- Select the lArgument variable from the Arguments to the function drop-down list.
-
Create the variable
sOutput
for the Assign the output to variable field.
-
Insert a Message box
action to hold the Python function output:
- Double-click or drag the Message box > Message box action.
- In the Enter the message to display field, select and insert the variable sOutput.
- Select the Close message box after option. Retain the default value of 5 seconds in the field.
-
Close the script execution session with a Python Script > Close
action:
- Double-click or drag Python Script > Close.
- Click Save.
-
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.