Python UIPath-无法从UIPath读取参数并将其传递给python代码 [英] Python UIPath - Unable to read arguments from UIPath and pass it to the python code

查看:576
本文介绍了Python UIPath-无法从UIPath读取参数并将其传递给python代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是显示Python作用域活动的图像:

Here is an image showing Python scope activity:

我正在尝试使用Python范围,Python加载活动,调用python方法并获取python对象(如下所述)在UIPath中执行脚本:

I am trying to execute a script in UIPath using Python scope, Python load activity, invoke python method and get python object which is mentioned below:

执行已完成,没有任何错误/异常.但是没有写入.xlsx文件. 代码未执行/参数未正确传递. 请帮助.

The execution is getting completed without any errors/exceptions. But there is no .xlsx file written. The code is not getting executed/ the arguments are not passed correctly. Kindly help.

import sys
import pandas as pd
import xlsxwriter
def excel_data (arg1,arg2,arg3,arg4):
    df = pd.DataFrame({‘SODA RISK’: [arg1,arg2,arg3,arg4]}) 
    writer = pd.ExcelWriter(‘try_python.xlsx’, engine=‘xlsxwriter’) 
    df.to_excel(writer,sheet_name=‘Sheet1’) 
    writer.save()

推荐答案

由于您的代码执行没有任何错误,因此将有一个Excel文件.您没有提供自定义路径,因此很可能在NuGet软件包文件夹中创建文件(您的用户名和软件包版本很可能会不同):

Since your code executes without any error, there will be an Excel file. You did not provide a custom path, so the file most likely gets created in the NuGet package folder (your user's name and the package versions most likely will be different):

C:\Users\foo\.nuget\packages\uipath.python.activities\1.1.6863.33404\lib\net452

您可能需要更改代码,以便可以将完整路径作为参数提供:

You may want to change your code so that the full path can be provided as an argument:

import sys
import pandas as pd
import xlsxwriter

def excel_data (fullPath, arg1, arg2, arg3, arg4):
    df = pd.DataFrame({'SODA RISK': [arg1,arg2,arg3,arg4]}) 
    writer = pd.ExcelWriter(fullPath, engine='xlsxwriter') 
    df.to_excel(writer,sheet_name='Sheet1') 
    writer.save()

此外,由于您的方法不返回任何内容,因此您可以摆脱Get Python Object活动.如果出现错误(例如缺少包),UiPath将引发异常.

Also, since your method does not return anything you could just get rid of the Get Python Object activity. If there's an error (e.g. a missing package), UiPath will throw an exception.

这篇关于Python UIPath-无法从UIPath读取参数并将其传递给python代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆