activities
latest
false
- 概述
- 加密
- 数据库
- Java
- Python
- 网页 API
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。
新发布内容的本地化可能需要 1-2 周的时间才能完成。
开发者活动
上次更新日期 2026年5月21日
以下示例说明如何自动运行在运行时创建的 Python 代码并写入文件日志。它显示了诸如“Python 作用域”和“运行 Python 脚本”之类的活动。您可以在“UiPath.Python.Activities ”包中找到这些活动。
备注:
Before running any Python workflow, make sure that you have Python3 installed.
此自动化流程的构建方法如下:
-
打开 Studio ,创建一个新“流程”。
-
将“序列”容器拖动至“工作流设计器”。
-
创建新参数:
参数名称 方向 参数类型 默认值 in_PythonPath输入 字符串 添加已安装 Python 的文件夹的路径 -
Drag an If activity inside the Sequence container.
- 在“条件”字段中添加表达式“
String.IsNullOrEmpty(in_PythonPath) orelse not Directory.Exists(in_PythonPath)”。
- 在“条件”字段中添加表达式“
-
将“序列”容器拖动到“If 条件”活动的“Then”字段中。
-
Drag a Message Box activity inside the Sequence container.
- In the Properties panel, add the expression
"Error"in the Caption field. - 在“文本”字段中添加表达式
"Pyhon Path not configured. Please configure path by setting the argument 'in_PythonPath'."。
- In the Properties panel, add the expression
-
将“终止工作流”活动拖动至“消息框”活动之后。
- In the Properties panel, add the expression
"Input Arguments not correct"in the Reason field.
- In the Properties panel, add the expression
-
将“Python 作用域”活动拖动至“If条件”活动后。
- In the Properties panel, add the argument
in_PythonPathin the Path field. - Select your Python version from the Version drop-down list (Python_36 in this example).
- In the Properties panel, add the argument
-
Drag a Run Python Script activity inside the Python Scope container.
- In the Properties panel, add the following code snippet in the Code field:
String.Format( "import sys" + Environment.NewLine _ + "import os " + Environment.NewLine _ + "with open('{0}\logs.txt', 'w') as f: " + Environment.NewLine _ + " f.write('Starting script! \n')" + Environment.NewLine _ + " f.write('Computing!\n')" + Environment.NewLine _ + " f.write('Finishing script! \n')" + Environment.NewLine, _ Directory.GetCurrentDirectory.Replace("\", "\\"))String.Format( "import sys" + Environment.NewLine _ + "import os " + Environment.NewLine _ + "with open('{0}\logs.txt', 'w') as f: " + Environment.NewLine _ + " f.write('Starting script! \n')" + Environment.NewLine _ + " f.write('Computing!\n')" + Environment.NewLine _ + " f.write('Finishing script! \n')" + Environment.NewLine, _ Directory.GetCurrentDirectory.Replace("\", "\\"))
- In the Properties panel, add the following code snippet in the Code field:
-
运行流程。 自动化运行 Python 代码,并在名为
logs.txt的文件中写入日志。