How to run a python script with entering arguments

Check this example for a Windows project with VB language.

  1. In the Studio machine install Python 3.10.10 64-bit from here https://www.python.org/ftp/python/3.10.10/python-3.10.10-amd64.exe . After installing it, you need to restart the machine.

  2. In the Studio machine, for Windows projects, the Python Scope activity requires you to install the .NET Desktop Runtime 5.0.17. After installing it, you need to restart the machine.

  3. In your project add the UiPath.Python.Activities[1.6.0] package.

  4. Add a Python Scope activity and configure it as below (modify the values with your installation path):

Library path: "C:\Users\your_username\AppData\Local\Programs\Python\Python310\python310.dll"

Path: "C:\Users\your_username\AppData\Local\Programs\Python\Python310"

Target: x64

Version: Python >=3.10

  1. Create a python script with name MathOperations.py that will have this content:
def add(num1,num2):
	return num1 + num2
	
def dif(num1,num2):
	return num1 - num2
  1. Add a Load Python Script activity and configure it as below:

File: "MathOperations.py"

Result: pyScriptOut (create a variable with Ctrl + k)

  1. Add an Invoke Python Method activity and configure it as below:

InputParameters: Array.ConvertAll({5,4}, Function(x) CType(x, Object))

Instance: pyScriptOut

Name: "add"

Result: pyOutput (create a variable with Ctrl + k)

  1. Add a Get Python Object activity and configure it as below:

PythonOject: pyOutput

TypeArgument: Int32

Name: “add”

Result: addOperationOutput (create a variable with Ctrl + k)

  1. Add a Log Message activity and configure it as below:

LogLevel: LogLevel.Info

Message: addOperationOutput

  1. In the Variables panel check if the variables have the correct type:

  1. If you will run the file, the result will be 9.

image