pythonpython-3.xuipath

Python UIPath - Unable to read arguments from UIPath and pass it to the python code


Here is an image showing Python scope activity:

Image shows python scope activity

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:

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()

Solution

  • 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()
    

    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.