Step-By-Step Guide to Use Python Script in Automation

Let's see an example to automate the execution of the Python script - list.py where a list of default integers are defined and takes a list of floating numbers and an integer as inputs. The Python script is created using the parser for command- line options and arguments to print the input values.

 

Below is the Python script:

 

 

The Python script can be run in the command line and prints the help and error handling messages.

 

 

To automate the printing of input values using the Python script:

  1. Configure the path of the .exe file of Python as an Environment Variable- PYTHON_PATH.
  2. Create a new process.
  3. In the Parameter bar, create an In arguments as X and listb of type Int32, and define their respective default values. These arguments are used to pass the named input parameters.
  4. In the Parameter bar, create an In/Out argument, Result of type String to store the output of the Python script.

 

 

  1. From the Canvas Tools panel, add the Python Script to the Flowchart designer on the Canvas.
  2. Click Add Script to browse and select the list.py Python script.
  3. Click the (Settings) icon. The Input Parameters dialog box opens.
  4. Click Add to add a new row.
  5. In the Delimiters list, select--, and then select the IsNamed check box to indicate that the input parameter is a named parameter.
  6. In the Parameter Name field, enter the text - Value of x.
  7. In the Parameter Value list, select the X argument created above.
  8. Click Add to add another row.
  9. In the Delimiters list, select--, and then select the IsNamed check box to indicate that the input parameter is a named parameter.
  10. In the Parameter Name field, enter the text - Value of listb.
  11. In the Parameter Value list, select listb argument created above.

 

 

  1. Click CONFIRM to save the details.
  2. In the Properties pane of the Python Script activity, select the Result parameter in the PythonOutputParam field.

 

 

To view the output in Automation Studio, let's add WriteLine activity. You can assign this process to a robot, if you want to execute this process outside Automation Studio.

  1. Add a WriteLine activity below the Python Script activity. In the Text field, enter Result to print the value returned after the execution of the Python script, list.py.

 

 

  1. Save the process.
  2. Setup the environment and then perform a test run.

 

 

The Output console displays the defined input values as per the Python script.