> ## Documentation Index
> Fetch the complete documentation index at: https://rpa.bazhuayu.com/helpcenter/llms.txt
> Use this file to discover all available pages before exploring further.

# 执行Python代码

## 指令说明

**描述：** 执行Python代码，同时获取输出结果

## 参数说明

<Tabs>
  <Tab title="常规">
    <img src="https://mintcdn.com/bazhuayu-rpa-docs/y7Z2TvwRJJef-uiI/helpcenter/commands/others/images/executepythonmodulecommand-01.png?fit=max&auto=format&n=y7Z2TvwRJJef-uiI&q=85&s=46ca8d5d2b0e1e3c5c616cdd29e1a8d0" alt="执行Python代码指令参数面板" width="644" height="693" data-path="helpcenter/commands/others/images/executepythonmodulecommand-01.png" />

    | 参数            | 说明                                                     |
    | ------------- | ------------------------------------------------------ |
    | **Python代码段** | python代码需要以函数形式编写和执行                                   |
    | **执行函数**      | 选择需要执行代码段中的哪一个函数                                       |
    | **输入参数**      | 流程变量以函数入参方式传入，如main(a,b)函数包含a,b两个入参，当选择执行函数时可传入a,b流程变量 |
    | **结果保存至**     | 指定一个变量名称，该变量用于保存python代码执行函数后return的返回值                |
  </Tab>

  <Tab title="高级">
    | 参数               | 说明                                 |
    | ---------------- | ---------------------------------- |
    | **使用本机Python环境** | 勾选则使用的是本机的Python环境                 |
    | **检测方式**         | 自动检测系统可用的Python环境 使用指定目录下的Python环境 |
  </Tab>
</Tabs>

## 使用示例

<img src="https://mintcdn.com/bazhuayu-rpa-docs/y7Z2TvwRJJef-uiI/helpcenter/commands/others/images/executepythonmodulecommand-03.png?fit=max&auto=format&n=y7Z2TvwRJJef-uiI&q=85&s=11382c52dd2a710e6c957405a3716978" alt="执行Python代码使用示例" width="642" height="684" data-path="helpcenter/commands/others/images/executepythonmodulecommand-03.png" />

<img src="https://mintcdn.com/bazhuayu-rpa-docs/y7Z2TvwRJJef-uiI/helpcenter/commands/others/images/executepythonmodulecommand-02.png?fit=max&auto=format&n=y7Z2TvwRJJef-uiI&q=85&s=1895d16498834549277f84024955eb04" alt="执行Python代码使用示例 - 流程搭建" width="701" height="157" data-path="helpcenter/commands/others/images/executepythonmodulecommand-02.png" />

**该流程执行逻辑：**

1. 在【执行Python代码】中编写 `main(a, b, c)`，让函数返回三个参数之和；需要第三方包时可在代码中直接导入。
2. 选择 `main` 作为入口函数，依次传入 `a=1`、`b=2`、`c=3`，并把返回值保存到“脚本输出”。
3. 执行后使用【打印日志】输出“脚本输出”，结果为 `6`。

入口参数和返回值支持 `string`、`bool`、`int`、`float`、`list`、`dict`；其他类型需在代码中自行转换。

### 效果展示

<img src="https://mintcdn.com/bazhuayu-rpa-docs/y7Z2TvwRJJef-uiI/helpcenter/commands/others/images/executepythonmodulecommand-04.png?fit=max&auto=format&n=y7Z2TvwRJJef-uiI&q=85&s=6d4b929cb3062db0d350226e2bc40e55" alt="执行Python代码使用示例 - 效果展示" width="1341" height="216" data-path="helpcenter/commands/others/images/executepythonmodulecommand-04.png" />

<Info>
  使用指令过程中遇到问题？前往 [八爪鱼RPA 开发者社区问答板块](https://rpa.bazhuayu.com/community/questions) 提问，获取官方与社区帮助。
</Info>
