Hello, I had tried with a test Script.py file and a file Model.csv
In an empty new project, I had added the Python activity libraries.
Then from UIPath.Python.Activities I added a Python Scope activity.
At Library Path property of Python Scope I have the next setting:
string.Format(“{0}\AppData\Local\Programs\Python\Python37-32\python37.dll”,
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile))
And for the Python Path, I have:
string.Format("{0}\AppData\Local\Programs\Python\Python37-32",
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile))
For simplicity, I used a Set Variable action for the path to a csv file.
path = “./Model.csv”
Then I used a Load Python Script action.
The File property is set to “./Script.py”
Also for the Output Result I had declared an obj variable.
This obj variable is of type: “UIPath.Python.PythonObject”
Next I had added an Invoke Python Method
At Input Parameters I have a list of arguments like this: { path }
Where path is the file name for the “Model.csv” file.
Here comes that obj variable, that has to be placed at Instance.
For the Name of the function, I have a method called “read_model”.
This one I had defined into the “Script.py” file.
For editing the Python script, I had used an application called IDLE.
What really matters it’s the way, the arguments are being passed.
Here it is the code for this script file:
import sys
import csv
import os
def read_model(*args):
pad = args[0]
if (pad == “”): return
if (not os.path.exists(pad)): return
print(pad)
csvfile = open(pad)
reader = csv.reader(csvfile)
for line in reader:
print(line)
str = line
csvfile.close()
return
#read_model(“./Model.csv”)
#EOF
You can change this script file as you need.
At this moment it doesn’t give any errors and it seems it works.
For your understanding, this is the way the actions are being placed.
Please see the next image:
Hopefully, this would be of any help. I think, I learned a lot from this example.
With fine regards, Adrian Brinas.