Get python object

How to initialize python object ?

Hi, I had tried myself the next sequence of Python activities:
Please see the next picture:

In the Python Scope, the first activity is Load Python Script.
I have a Python file, which has a relative path: “./”.
This is the argument File of the Load Python Script activity.
The output from Load Python Script can be a new variable obj
The type of this obj should be “UIPath.Python.Python Object”

In this script, the input argument is reffered as: args[0]
Actually it is a path string to a file, that I want to read.
If I use args[1] for one single argument, I can get an error.
This file has been edited with IDLE 3.7 (32 bit).

After Load Python Script I used Invoke Python Method activity.
As input arguments I have a list with just one string item:
{ path }
The Instance is the obj variable about I had written before.
Name is the method I want to call. I have a method read_file
At Output, it is also used the obj variable for the Result.

The last one after Invoke is the Get Python Object activity.
Here is the part, where I also got several unhandled errors.
It was about conversion errors of Python obj to another type.
Obviously the input object is the PythonObject named as obj.
The TypeArgument is preselected as a generic System.Object
And for the Output I have a new Result variable named result.

If I declare result as an Object, everything it works fine.
When I use a String, or an Integer, it throws an exception.
Using a wrong type, could result to something like an error.
So, if I need a String, I converted this result to a String.
Unlike other methods, a generic type Object can be accepted.
This is because Object is the root for all other NET objects.
And a conversion from System.Object to another type can work.

Hope this can be of any help, Adrian.

@Adrian_Brinas I have encountered a similar issue (Get Python Object: Error converting Python object). My python script can return either a string output or JSON output. In the “Get Python Object” method, I declared the output variable as Object and I am getting an error. I am getting this error, irrespective of the data type of the variable. Appreciate it, if you could pls help me.