活动
最新
False
横幅背景图像
开发者活动
上次更新日期 2024年4月23日

调用 Python 脚本

To exemplify how to use this activity package, we have built an automation process to invoke a Python script which defines two operations, Add and Subtract. One of the methods, Add, is then called from the script and given a list of integer variables as input parameters. The result, stored in a proprietary PythonObject variable, is then converted into a .NET datatype to be further used in Studio.
注意: 您要使用的 Python 版本必须安装在要运行流程的计算机上。

该演示示例的构建方法如下:

  1. 打开 Studio 并启动新 流程
  2. 将“ Python 作用域 ”活动拖动到“ 工作流设计器”。
  3. 在“ Python 作用域 ”活动的“ 路径 ”属性中指定 Python 的安装目录。 默认情况下,位置为 %LOCALAPPDATA%\Programs\Python\PythonXX\python.exe,其中 XX 是您正在使用的 Python 版本。
  4. 在“ Python 作用域 ”的“ 执行” 部分中拖动“ 加载 Python 脚本 ”活动,并在“ 文件 ”属性中将文件路径添加到 MathOperations.py Python 脚本。
  5. 创建一个名为 MathFunctions 的新 PythonObject 变量,并将其添加到“ 结果 ”属性字段中。
  6. 添加“ 调用 Python 方法 ”活动并配置其属性,如下所示:

    • 输入参数 - {2,3}
    • 实例 ” - 将第 5 步中创建的变量 MathFunctions添加到此字段。
    • 名称 ” - 在要使用的脚本中添加方法的名称,在本例中为 add
    • 结果 - 创建一个名为 SumResultPython的新 PythonObject 变量,并将其添加到此属性字段中。
  7. 接下来,将 “获取 Python 对象 ”活动拖动到工作流中。 配置其属性,如下所示:

    • Python 对象 - 将 SumResultPython 变量添加到此字段。
    • 类型参数 - 从下拉列表中选择 Int32
    • 结果 - 创建一个名为 Result 的新 Int32 变量,并将其添加到此字段中。
  8. 在项目末尾添加一个 “消息框” 活动,并将其配置为显示 Result 变量。

    您的项目应如下所示:



  9. 运行流程。 消息框 显示“ 添加 ”方法的结果。

此页面是否有帮助?

获取您需要的帮助
了解 RPA - 自动化课程
UiPath Community 论坛
Uipath 白色徽标
信任与安全
© 2005-2024 UiPath. All rights reserved.