I want to run a python script from UiPath Studio and save the result obtained from it in a variable. Followed various videos and the explanations on various sites but not able to do it. Please help me if anyone have any idea.
I have used the below flow:
Python Scope: Gave the Python 3.6 path saved in Environment variables and selected Python_36
Load Python Script: Select the path of the python file
Invoke Python Method: Gave the o/p of Load python in Instance and gave the method name
Get python Object: Gave the o/p of Invoke Python in Python Object and saved the result in variable
But I am getting the error in 2nd step itself: Load Python Script: Error loading Python script
I get the same message if my code contains any errors. Could you try with a file/script only containing some really simple function and see if you get the same?
Please find the attached file.
Below is the python code for reference:
import sys
def total():
f = open(“./Sample.txt”, “r”)
searchlines = f.readlines()
f.close()
for i, line in enumerate(searchlines):
if “Total” in line:
for l in searchlines[i+1:i+2]:
total = l.strip()
return total
UiPath complained that it couldn’t find the file “.\Sample.txt”, and when I gave the full path to Sample.txt it worked. I don’t know if that cause you any issue but try something like this:
f = open(r"C:\Users\user\Documents\For forum\python\Sample.txt", “r”)